// var i;
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_ElementConfig = require("./AL_GAME_HUA_ElementConfig");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_LatticeConfig = require("./AL_GAME_HUA_LatticeConfig");
// var AL_GAME_HUA_LevelConfig = require("./AL_GAME_HUA_LevelConfig");
// var AL_GAME_HUA_PropConfig = require("./AL_GAME_HUA_PropConfig");
// var AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
// var AL_GAME_HUA_GameBase = require("./AL_GAME_HUA_GameBase");
// var AL_GAME_HUA_GamePool = require("./AL_GAME_HUA_GamePool");
// var AL_GAME_HUA_PropTips = require("./AL_GAME_HUA_PropTips");
// var AL_GAME_HUA_Element = require("./AL_GAME_HUA_Element");
// var AL_GAME_HUA_ElementAllocator = require("./AL_GAME_HUA_ElementAllocator");
// var AL_GAME_HUA_Lattice = require("./AL_GAME_HUA_Lattice");
// var AL_GAME_HUA_CrashEffect = require("./AL_GAME_HUA_CrashEffect");
// var S = cc._decorator;
// var w = S.ccclass;
// var Y = S.property;
// var E =
//     (S.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.node_layer_back = null;
//             t.node_layer_lattice = null;
//             t.node_layer_element = null;
//             t.node_layer_1_finger = null;
//             t.button_prop_tips = null;
//             t.array_lattice_list = [];
//             t.map_lattice_list = [];
//             t.elements = [];
//             t.map_element_list = {};
//             t.is_touch_move_state = !1;
//             t.lock_lattice = [];
//             t.mapSize = null;
//             t.levelData = null;
//             t.latticeConfig = null;
//             t.totalLayer = 0;
//             t.elementAllocator = null;
//             t.chooseElement = null;
//             t.gameStep = 0;
//             t.handleStep = 0;
//             t.levelGuide = -1;
//             t.videoLatticeGuide = -1;
//             t.isGameStuck = !1;
//             t.recordConf = {};
//             t.isTipping = !1;
//             t.tipsDuration = 0;
//             t.timeTipsDuration = 10;
//             t.latticeTipsDuration = 0;
//             t.tipsCD = 0;
//             t.enabledGuide = !1;
//             t.isGuiding = !1;
//             t.guideDuration = 0;
//             t.guideGroup = [];
//             t.curTipButton = null;
//             t.touchIds = [];
//             t.lastIdx = -1;
//             t.displaceProducts = [];
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.onPreload = function () {
//             return __awaiter(this, void 0, void 0, function () {
//                 return __generator(this, function (e) {
//                     switch (e.label) {
//                         case 0:
//                             console.log("******chushihua_ditu_peizhi");
//                             this.chushihua_ditu_peizhi();
//                             console.log("******yibu_jiazai_yuansu");
//                             return [4, this.yibu_jiazai_yuansu()];
//                         case 1:
//                             e.sent();
//                             return [2];
//                     }
//                 });
//             });
//         };
//         t.prototype.onPrepare = function () {
//             return __awaiter(this, void 0, void 0, function () {
//                 return __generator(this, function (e) {
//                     switch (e.label) {
//                         case 0:
//                             return [4, this.xianshi_yuansu_list()];
//                         case 1:
//                             e.sent();
//                             return [2];
//                     }
//                 });
//             });
//         };
//         t.prototype.chuli_youxi_kaishi = function () {
//             return __awaiter(this, void 0, void 0, function () {
//                 return __generator(this, function () {
//                     this.jiancha_yindao();
//                     this.chushihua_chumo_shijian();
//                     return [2];
//                 });
//             });
//         };
//         t.prototype.chuli_youxi_shengli = function () {
//             this.node.off(cc.Node.EventType.TOUCH_START, this.handle_event_touch_start, this);
//             this.node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_event_touch_move, this);
//             this.node.off(cc.Node.EventType.TOUCH_END, this.handle_event_touch_end, this);
//             this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_event_touch_end, this);
//         };
//         t.prototype.chuli_youxi_shibai = function () {
//             this.node.off(cc.Node.EventType.TOUCH_START, this.handle_event_touch_start, this);
//             this.node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_event_touch_move, this);
//             this.node.off(cc.Node.EventType.TOUCH_END, this.handle_event_touch_end, this);
//             this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_event_touch_end, this);
//         };
//         t.prototype.chuli_youxi_zhanting = function () {
//             cc.director.getScheduler().pauseTarget(this);
//         };
//         t.prototype.chuli_youxi_jixu = function () {
//             cc.director.getScheduler().resumeTarget(this);
//         };
//         t.prototype.chuli_youxi_tuichu = function () {};
//         t.prototype.chuli_zhen_gengxin = function (e) {
//             this.gengxin_daoju_tishi(e);
//             this.gengxin_yindao(e);
//         };
//         t.prototype.gengxin_daoju_tishi = function (e) {
//             var t = this;
//             if (!this.isTipping) {
//                 var n = AL_GAME_HUA_GameConst.GameConst.getInstance().tips_duration;
//                 var o = AL_GAME_HUA_Instance.Instance.Game.gameUI;
//                 if (
//                     this.tipsDuration >= AL_GAME_HUA_GameConst.GameConst.getInstance().tips_prop_time &&
//                     this.tipsCD > n
//                 ) {
//                     var i = [
//                         {
//                             button: o.propButtons[0],
//                             tipIdx: 0,
//                             weight: 90
//                         }
//                     ];
//                     this.xianshi_daoju_tishi_suiji(i, function () {
//                         t.tipsDuration = 0;
//                     });
//                 } else {
//                     this.tipsDuration += e;
//                 }
//                 if (
//                     AL_GAME_HUA_Instance.Instance.Game.huoqu_shengyu_shijian() < 60 &&
//                     !AL_GAME_HUA_Instance.Instance.Game.isTimePause
//                 ) {
//                     if (
//                         this.timeTipsDuration >= AL_GAME_HUA_GameConst.GameConst.getInstance().time_prop_time &&
//                         this.tipsCD > n
//                     ) {
//                         var r = o.propButtons[3];
//                         this.xianshi_daoju_tishi_suiji(
//                             [
//                                 {
//                                     button: r,
//                                     tipIdx: 3,
//                                     weight: 100
//                                 }
//                             ],
//                             function () {
//                                 t.timeTipsDuration = 0;
//                             }
//                         );
//                     } else {
//                         this.timeTipsDuration += e;
//                     }
//                 }
//                 this.latticeTipsDuration >= AL_GAME_HUA_GameConst.GameConst.getInstance().video_lattice_duration &&
//                 this.tipsCD > n
//                     ? this.xianshi_wangge_tishi(function () {
//                           t.latticeTipsDuration = 0;
//                       })
//                     : (this.latticeTipsDuration += e);
//                 if (this.isGameStuck && this.tipsCD > 2) {
//                     i = [
//                         {
//                             button: o.propButtons[1],
//                             tipIdx: 5,
//                             weight: 60
//                         },
//                         {
//                             button: o.propButtons[2],
//                             tipIdx: 4,
//                             weight: 30
//                         }
//                     ];
//                     this.xianshi_daoju_tishi_suiji(i, function () {});
//                 }
//                 this.tipsCD += e;
//             }
//         };
//         t.prototype.gengxin_yindao = function (e) {
//             var t = this;
//             if (this.enabledGuide && !this.isGuiding) {
//                 if (this.guideDuration >= AL_GAME_HUA_GameConst.GameConst.getInstance().guide_duration) {
//                     var n = {};
//                     var o = function (e) {
//                         var t = i.array_lattice_list[e];
//                         if (t.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                             t.bianli_layer_list(function (e) {
//                                 if (!t.shifou_suoding) {
//                                     if (e.idx in n == 0) {
//                                         n[e.idx] = [];
//                                     }
//                                     n[e.idx].push(e);
//                                 }
//                             });
//                         } else {
//                             if (t.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                                 var o = t.huoqu_single_yuansu();
//                                 if (o) {
//                                     if (o.idx in n == 0) {
//                                         n[o.idx] = [];
//                                     }
//                                     n[o.idx].push(o);
//                                 }
//                             }
//                         }
//                     };
//                     var i = this;
//                     for (var r = 0; r < this.array_lattice_list.length; r++) {
//                         o(r);
//                     }
//                     var a = [];
//                     for (var s in n)
//                         if (n[s].length >= 3) {
//                             a.push(s);
//                         }
//                     if (a.length > 0) {
//                         var c = a.huoqu_shuzu_zhong_suiji_yige_yuansu();
//                         n[c].forEach(function (e) {
//                             if (!(t.guideGroup.length >= 3)) {
//                                 e.chuli_yindao();
//                                 t.guideGroup.push(e);
//                             }
//                         });
//                         this.isGuiding = !0;
//                     }
//                     this.guideDuration = 0;
//                 } else {
//                     this.guideDuration += e;
//                 }
//             }
//         };
//         t.prototype.yichu_yindao = function () {
//             this.guideGroup.forEach(function (e) {
//                 e.reset();
//             });
//             this.guideGroup = [];
//             this.isGuiding = !1;
//         };
//         t.prototype.xianshi_wangge_tishi = function (e, t) {
//             var n = this;
//             if (!t) {
//                 var o = this.array_lattice_list.filter(function (e) {
//                     return e.isVideoLock;
//                 });
//                 if (0 == o.length) {
//                     return void (this.latticeTipsDuration = Number.MIN_SAFE_INTEGER);
//                 }
//                 t = o.huoqu_shuzu_zhong_suiji_yige_yuansu();
//             }
//             this.yincang_daoju_tishi();
//             this.isTipping = !0;
//             this.button_prop_tips.onHide = function () {
//                 n.isTipping = !1;
//                 n.tipsCD = 0;
//                 if (e) {
//                     e();
//                 }
//             };
//             this.button_prop_tips.show(t.node, "空货柜引导", cc.v2(50, 10));
//         };
//         t.prototype.xianshi_daoju_tishi_suiji = function (e, t) {
//             this.yincang_daoju_tishi();
//             var n = 0;
//             var o = 0;
//             for (var i = e; o < i.length; o++) {
//                 var r = (u = i[o]).button;
//                 if (!r.huoqu_shifou_jiesuo()) {
//                     u.weight = 0;
//                 }
//                 if (0 == r.huoqu_shuliang()) {
//                     u.weight /= 1e6;
//                 }
//                 n += u.weight;
//             }
//             var a = Math.get_random(0, n);
//             var s = 0;
//             var c = 0;
//             for (var l = e; c < l.length; c++) {
//                 var u;
//                 if ((s += (u = l[c]).weight) > a) {
//                     return void this.xianshi_daoju_tishi(u.button, u.tipIdx, function () {
//                         if (t) {
//                             t();
//                         }
//                     });
//                 }
//             }
//             if (t) {
//                 t();
//             }
//         };
//         t.prototype.xianshi_daoju_tishi = function (e, t, n) {
//             var o = this;
//             this.isTipping = !0;
//             e.breath_donghua();
//             this.curTipButton = e;
//             this.button_prop_tips.onHide = function () {
//                 o.isTipping = !1;
//                 o.tipsCD = 0;
//                 e.tingzhi_donghua();
//                 o.curTipButton = null;
//                 if (n) {
//                     n();
//                 }
//             };
//             this.button_prop_tips.show(
//                 e.node,
//                 ["消除3个物品", "刷新所有物品", "变换9个物品", "冻结15秒", "变换9个物品2", "刷新所有物品2"][t]
//             );
//         };
//         t.prototype.yincang_daoju_tishi = function () {
//             if (this.button_prop_tips) {
//                 this.button_prop_tips.hide();
//             }
//             if (this.curTipButton) {
//                 this.curTipButton.tingzhi_donghua();
//                 this.curTipButton = null;
//             }
//             this.isTipping = !1;
//         };
//         t.prototype.chushihua_ditu_peizhi = function () {
//             var e;
//             var t = AL_GAME_HUA_GameData.GameData.getInstance();
//             if (AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.NORMAL) {
//                 e = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_peizhi_by_level(t.huoqu_yijiesuo_guanqia());
//             } else {
//                 if (AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.CHALLENGE) {
//                     e = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_peizhi_by_date(
//                         AL_GAME_HUA_Instance.Instance.ChallengeLevel
//                     );
//                 } else {
//                     if (AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.SPECIAL) {
//                         var n = Math.min(
//                             t.huoqu_yijiesuo_teshu_guanqia(),
//                             AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_zong_shuliang()
//                         );
//                         e = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_peizhi_by_level(n);
//                     }
//                 }
//             }
//             this.levelData = e;
//             var o = e.shelf_type;
//             var i = e.Lattce;
//             var r = e.Specialgrid2;
//             this.chuangjian_ditu_by_leixing(o, i, r);
//             this.shengcheng_yuansu();
//         };
//         t.prototype.chushihua_chumo_shijian = function () {
//             this.node.on(cc.Node.EventType.TOUCH_START, this.handle_event_touch_start, this);
//             this.node.on(cc.Node.EventType.TOUCH_MOVE, this.handle_event_touch_move, this);
//             this.node.on(cc.Node.EventType.TOUCH_END, this.handle_event_touch_end, this);
//             this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.handle_event_touch_end, this);
//         };
//         t.prototype.handle_event_touch_start = function (e) {
//             if (!(this.touchIds.length >= 1)) {
//                 this.touchIds.push(e.getID());
//                 0 == AL_GAME_HUA_GameData.GameData.getInstance().handleMode
//                     ? this.handle_touch_start_0(e)
//                     : 1 == AL_GAME_HUA_GameData.GameData.getInstance().handleMode && this.handle_touch_start_1(e);
//             }
//         };
//         t.prototype.handle_event_touch_move = function (e) {
//             if (!(this.touchIds.length > 1)) {
//                 if (this.chooseElement) {
//                     if (!AL_GAME_HUA_Instance.Instance.Game.isStartTime) {
//                         AL_GAME_HUA_Instance.Instance.Game.isStartTime = !0;
//                     }
//                     0 == AL_GAME_HUA_GameData.GameData.getInstance().handleMode
//                         ? this.handle_touch_move_0(e)
//                         : 1 == AL_GAME_HUA_GameData.GameData.getInstance().handleMode && this.handle_touch_move_1(e);
//                 }
//             }
//         };
//         t.prototype.handle_event_touch_end = function (e) {
//             if (!(this.touchIds.length > 1)) {
//                 this.touchIds = [];
//                 if (this.chooseElement) {
//                     0 == AL_GAME_HUA_GameData.GameData.getInstance().handleMode
//                         ? this.handle_touch_end_0(e)
//                         : 1 == AL_GAME_HUA_GameData.GameData.getInstance().handleMode &&
//                           (this.is_touch_move_state || this.chooseElement.isMove ? this.handle_touch_end_0(e) : this.handle_touch_end_1(e));
//                     this.is_touch_move_state = !1;
//                 }
//             }
//         };
//         t.prototype.huoqu_zuobiao_suoyin = function (e, t) {
//             var n = -e.node_area_space.width / 2;
//             return Math.clamp(Math.floor((t.x - n) / (e.node_area_space.width / 3)), 0, 2);
//         };
//         t.prototype.chazhao_yuansu = function (e) {
//             var t = this.node.convertToNodeSpaceAR(e);
//             var n = this.weizhi_zhuanhuan_dao_wangge(t);
//             if (n) {
//                 if (n.type == AL_GAME_HUA_Define.Define.LatticeType.NULL) {
//                     return null;
//                 }
//                 if (n.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL && n.shifou_suoding) {
//                     this.touchIds = [];
//                     return null;
//                 }
//                 var o = n.node_area_space.convertToNodeSpaceAR(e);
//                 var i = this.huoqu_zuobiao_suoyin(n, o);
//                 var r = null;
//                 if (n.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                     if (1 == i && n.singlePos.length > 0) {
//                         r = n.huoqu_single_yuansu();
//                     }
//                 } else {
//                     if (n.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                         var a = n.huoqu_yuansiu_b_layer();
//                         if (n.huoqu_wangge_kong_shuliang() < 3) {
//                             a[i]
//                                 ? (r = a[i])
//                                 : 1 == i
//                                 ? (r = o.x > 0 ? (a[2] ? a[2] : a[0]) : a[0] ? a[0] : a[2])
//                                 : 2 == i
//                                 ? (r = a[1] ? a[1] : a[0])
//                                 : 0 == i && (r = a[1] ? a[1] : a[2]);
//                         }
//                     }
//                 }
//                 return r;
//             }
//             return null;
//         };
//         t.prototype.fanhui_dao_origin = function () {
//             this.handleStep++;
//             AL_GAME_HUA_Common.Common.vibrate(!1);
//             this.chooseElement.yidong_dao_weizhi();
//             this.jiancha_gezi_shifou_wancheng(this.chooseElement.belone);
//         };
//         t.prototype.fangru_wangge_zhong = function (e, t, n) {
//             this.gameStep++;
//             this.handleStep++;
//             var o = this.chooseElement.belone;
//             if (o != e) {
//                 o.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE
//                     ? (o.yichu_yuansu_from_single(), this.jiancha_dange_gezi_zhuangtai(o))
//                     : o.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL &&
//                       (o.yichu_yuansu(this.chooseElement), this.jiancha_wangge_kong_zhuangtai(o) && (n.check = !0));
//                 if (e.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                     e.tianjia_yuansu_to_single(this.chooseElement);
//                     this.jiancha_dange_gezi_zhuangtai(e);
//                 } else {
//                     if (e.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                         var i = this.huoqu_zuobiao_suoyin(e, t);
//                         e.tianjia_yuansu(this.chooseElement, i);
//                         if (this.jiancha_gezi_shifou_wancheng(e)) {
//                             n.check = !0;
//                             n.complete = !0;
//                         }
//                     }
//                 }
//             } else {
//                 e.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE
//                     ? ((this.is_touch_move_state || this.chooseElement.isMove) && this.chooseElement.yidong_dao_weizhi(),
//                       (n.same = !0))
//                     : e.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL &&
//                       ((i = this.huoqu_zuobiao_suoyin(e, t)) != this.chooseElement.posIdx ||
//                       this.is_touch_move_state ||
//                       this.chooseElement.isMove
//                           ? (e.yichu_yuansu(this.chooseElement),
//                             e.tianjia_yuansu(this.chooseElement, i),
//                             this.jiancha_gezi_shifou_wancheng(e) && ((n.check = !0), (n.complete = !0)))
//                           : (n.same = !0));
//             }
//         };
//         t.prototype.handle_touch_start_0 = function (e) {
//             var t = e.getLocation();
//             var n = this.node.convertToNodeSpaceAR(t);
//             var o = this.chazhao_yuansu(t);
//             if (o) {
//                 this.chooseElement = o;
//                 AL_GAME_HUA_Common.Common.bofang_yinxiao("m3d_click", this);
//                 if (-1 != this.guideGroup.indexOf(this.chooseElement)) {
//                     this.yichu_yindao();
//                 }
//                 o.chuli_xuanze_zhuangtai();
//                 o.shezhi_miaobian(!0);
//                 o.chuli_tuodong_zhuangtai();
//                 var i = cc.v2(0, AL_GAME_HUA_Define.Define.FINGER_OFFSET);
//                 o.node.setPosition(n.add(i));
//             }
//         };
//         t.prototype.handle_touch_move_0 = function (e) {
//             var t = this.node.convertToNodeSpaceAR(e.getLocation());
//             this.chooseElement.node.setPosition(t.add(cc.v2(0, AL_GAME_HUA_Define.Define.FINGER_OFFSET)));
//         };
//         t.prototype.handle_touch_start_1 = function (e) {
//             var t = e.getLocation();
//             var n = this.node.convertToNodeSpaceAR(t);
//             var o = this.weizhi_zhuanhuan_dao_wangge(n);
//             if (o) {
//                 if (o.type == AL_GAME_HUA_Define.Define.LatticeType.NULL) {
//                     return;
//                 }
//                 if (o.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL && o.shifou_suoding) {
//                     return void (this.touchIds = []);
//                 }
//                 var i = o.node_area_space.convertToNodeSpaceAR(t);
//                 var r = this.huoqu_zuobiao_suoyin(o, i);
//                 var a = null;
//                 if (o.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                     if (1 == r) {
//                         if (this.chooseElement && !o.shifou_man) {
//                             if (o.jiancha_hit_rq(t)) {
//                                 var s = {
//                                     check: !1,
//                                     complete: !1,
//                                     same: !1
//                                 };
//                                 this.fangru_wangge_zhong(o, i, s);
//                                 return void this.jiancha_chumo_jieguo(s);
//                             }
//                             a = o.huoqu_single_yuansu();
//                         }
//                         if (!a) {
//                             a = o.huoqu_single_yuansu();
//                         }
//                     }
//                 } else {
//                     if (o.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                         if (this.chooseElement && !o.shifou_man) {
//                             if (o.jiancha_hit_rq(t)) {
//                                 s = {
//                                     check: !1,
//                                     complete: !1,
//                                     same: !1
//                                 };
//                                 this.fangru_wangge_zhong(o, i, s);
//                                 return void this.jiancha_chumo_jieguo(s);
//                             }
//                             if (!o.huoqu_yuansiu_b_layer()[r]) {
//                                 s = {
//                                     check: !1,
//                                     complete: !1,
//                                     same: !1
//                                 };
//                                 this.fangru_wangge_zhong(o, i, s);
//                                 return void this.jiancha_chumo_jieguo(s);
//                             }
//                         }
//                         var c = o.huoqu_yuansiu_b_layer();
//                         if (o.huoqu_wangge_kong_shuliang() < 3) {
//                             this.chooseElement
//                                 ? c[r] && (a = c[r])
//                                 : c[r]
//                                 ? (a = c[r])
//                                 : 1 == r
//                                 ? (a = i.x > 0 ? (c[2] ? c[2] : c[0]) : c[0] ? c[0] : c[2])
//                                 : 2 == r
//                                 ? (a = c[1] ? c[1] : c[0])
//                                 : 0 == r && (a = c[1] ? c[1] : c[2]);
//                         }
//                     }
//                 }
//                 if (a) {
//                     if (this.chooseElement) {
//                         this.chooseElement.reset();
//                     }
//                     this.chooseElement = a;
//                     AL_GAME_HUA_Common.Common.bofang_yinxiao("m3d_click", this);
//                     if (-1 != this.guideGroup.indexOf(this.chooseElement)) {
//                         this.yichu_yindao();
//                     }
//                     a.chuli_xuanze_zhuangtai();
//                     a.shezhi_miaobian(!0);
//                 }
//             }
//         };
//         t.prototype.handle_touch_move_1 = function (e) {
//             var t = this.chooseElement;
//             var n = this.node.convertToNodeSpaceAR(e.getLocation());
//             this.is_touch_move_state
//                 ? t.node.setPosition(n)
//                 : e.getLocation().sub(e.getStartLocation()).magSqr() >=
//                       Math.pow(AL_GAME_HUA_Define.Define.TOUCH_MOVE_LIMIT, 2) &&
//                   ((this.is_touch_move_state = !0), t.chuli_tuodong_zhuangtai(), t.node.setPosition(n));
//         };
//         t.prototype.handle_touch_end_0 = function () {
//             var e = cc.v2(0, this.chooseElement.node.height / 2).sub(cc.v2(0, AL_GAME_HUA_Define.Define.FINGER_OFFSET));
//             var t = this.chooseElement.node.getPosition().add(e);
//             var n = this.chooseElement.node.convertToWorldSpaceAR(e);
//             var o = this.weizhi_zhuanhuan_dao_wangge(t);
//             var i = {
//                 check: !1,
//                 complete: !1,
//                 same: !1
//             };
//             o
//                 ? o.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
//                     ? o.shifou_suoding || o.shifou_man
//                         ? this.fanhui_dao_origin()
//                         : this.fangru_wangge_zhong(o, o.node_area_space.convertToNodeSpaceAR(n), i)
//                     : o.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE
//                     ? o.shifou_man
//                         ? this.fanhui_dao_origin()
//                         : this.fangru_wangge_zhong(o, o.node_area_space.convertToNodeSpaceAR(n), i)
//                     : this.fanhui_dao_origin()
//                 : this.fanhui_dao_origin();
//             this.jiancha_chumo_jieguo(i);
//         };
//         t.prototype.handle_touch_end_1 = function () {};
//         t.prototype.jiancha_chumo_jieguo = function (e) {
//             if (e.check) {
//                 this.jiancha_youxi_shifou_bei_kazhu();
//             }
//             e.complete
//                 ? this.yincang_daoju_tishi()
//                 : (AL_GAME_HUA_Common.Common.bofang_yinxiao("put", this), AL_GAME_HUA_Common.Common.vibrate(!1));
//             if (!e.same) {
//                 this.chooseElement = null;
//             }
//         };
//         t.prototype.jiancha_yindao = function () {
//             var e = this;
//             if (AL_GAME_HUA_Instance.Instance.LevelType != AL_GAME_HUA_Define.Define.LevelType.CHALLENGE) {
//                 if (1 == AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia()) {
//                     if (-1 == this.levelGuide) {
//                         this.levelGuide = 0;
//                     }
//                     if (0 == this.levelGuide) {
//                         this.node_layer_1_finger.active = !0;
//                         var t = (r = this.elements[4]).belone.node.convertToWorldSpaceAR(
//                             cc.v2(AL_GAME_HUA_Define.Define.LATTICE_POS[r.posIdx])
//                         );
//                         var n = this.node_layer_1_finger.parent.convertToNodeSpaceAR(t);
//                         var o = (g = this.array_lattice_list[1].node).convertToWorldSpaceAR(
//                             AL_GAME_HUA_Define.Define.LATTICE_POS[2]
//                         );
//                         var i = this.node_layer_1_finger.parent.convertToNodeSpaceAR(o);
//                         this.shou_yidong_dongzuo(n, i);
//                     } else {
//                         if (1 == this.levelGuide) {
//                             var r;
//                             t = (r = this.elements[2]).belone.node.convertToWorldSpaceAR(
//                                 cc.v2(AL_GAME_HUA_Define.Define.LATTICE_POS[r.posIdx])
//                             );
//                             n = this.node_layer_1_finger.parent.convertToNodeSpaceAR(t);
//                             o = (g = this.array_lattice_list[0].node).convertToWorldSpaceAR(
//                                 AL_GAME_HUA_Define.Define.LATTICE_POS[0]
//                             );
//                             i = this.node_layer_1_finger.parent.convertToNodeSpaceAR(o);
//                             if (2 == this.array_lattice_list[0].huoqu_wangge_zhuangtai().same) {
//                                 this.shou_yidong_dongzuo(n, i);
//                             }
//                         } else {
//                             if (2 == this.levelGuide) {
//                                 this.node_layer_1_finger.active = !1;
//                             }
//                         }
//                     }
//                 }
//                 var a = AL_GAME_HUA_GameData.GameData.getInstance();
//                 var s = a.huoqu_yijiesuo_guanqia();
//                 var c = AL_GAME_HUA_PropConfig.PropConfig.getInstance();
//                 var l = [
//                     AL_GAME_HUA_PropConfig.PropId.TIPS_GAME,
//                     AL_GAME_HUA_PropConfig.PropId.REFRESH_GAME,
//                     AL_GAME_HUA_PropConfig.PropId.CHANGE_GAME,
//                     AL_GAME_HUA_PropConfig.PropId.TIME_GAME
//                 ];
//                 for (var f = 0; f < l.length; f++) {
//                     var h = l[f];
//                     var P = c.huoqu_peizhi_genju_id(h).unlock;
//                     if (!(a.huoqu_prop_jiesuo(h) || s != P)) {
//                         AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jiesuo_mianban({
//                             propButton: AL_GAME_HUA_Instance.Instance.Game.gameUI.propButtons[f]
//                         });
//                         a.shezhi_prop_jiesuo(h);
//                     }
//                 }
//                 var g;
//                 if (
//                     AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.NORMAL &&
//                     AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() ==
//                         AL_GAME_HUA_GameConst.GameConst.getInstance().video_lattice_unlock &&
//                     (-1 == this.videoLatticeGuide && (this.videoLatticeGuide = 0), 0 == this.videoLatticeGuide)
//                 ) {
//                     this.node_layer_1_finger.active = !0;
//                     t = (g = this.map_lattice_list[2][3]).node.convertToWorldSpaceAR(cc.v2(0, -20));
//                     n = this.node_layer_1_finger.parent.convertToNodeSpaceAR(t);
//                     this.node_layer_1_finger.setPosition(n);
//                     this.node_layer_1_finger.scale = 0.7;
//                     this.node_layer_1_finger.active = !0;
//                     this.node_layer_1_finger.stopAllActions();
//                     cc.tween(this.node_layer_1_finger)
//                         .to(0.5, {
//                             scale: 0.75
//                         })
//                         .to(0.5, {
//                             scale: 0.7
//                         })
//                         .union()
//                         .repeatForever()
//                         .start();
//                     this.xianshi_wangge_tishi(function () {
//                         e.node_layer_1_finger.active = !1;
//                     }, g);
//                     this.videoLatticeGuide++;
//                 }
//             }
//         };
//         t.prototype._jiancha_youxi_shifou_bei_kazhu = function () {
//             var e = 0;
//             var t = 0;
//             var n = {};
//             for (var o = 0; o < this.array_lattice_list.length; o++) {
//                 var i = this.array_lattice_list[o];
//                 if (i.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                     if (
//                         !i.shifou_suoding &&
//                         ((e += i.huoqu_wangge_kong_shuliang()),
//                         i.bianli_layer_list(function (e) {
//                             if (e.idx in n == 0) {
//                                 n[e.idx] = [];
//                             }
//                             n[e.idx].push(e);
//                         }),
//                         e >= 3)
//                     ) {
//                         return !1;
//                     }
//                 } else {
//                     if (
//                         i.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
//                         ((t += 3 - i.singlePos.length),
//                         i.singlePos.forEach(function (e) {
//                             if (e.idx in n == 0) {
//                                 n[e.idx] = [];
//                             }
//                             n[e.idx].push(e);
//                         }),
//                         t >= 3)
//                     ) {
//                         return !1;
//                     }
//                 }
//                 if (e + t >= 3) {
//                     return !1;
//                 }
//             }
//             if (e + t > 0) {
//                 var r = e + t;
//                 for (var a in n)
//                     if (n[a].length >= 3) {
//                         var s = 0;
//                         var c = 0;
//                         for (var l = n[a]; c < l.length; c++) {
//                             var u = l[c];
//                             if (u.belone.type != AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                                 if (u.belone.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                                     var p = u.belone.singlePos.indexOf(u);
//                                     if (3 == p) {
//                                         s++;
//                                         continue;
//                                     }
//                                     if (2 == p && r > 1) {
//                                         s++;
//                                         continue;
//                                     }
//                                 }
//                             } else {
//                                 s++;
//                             }
//                         }
//                         if (s >= 3) {
//                             this.tipsDuration = AL_GAME_HUA_GameConst.GameConst.getInstance().tips_prop_time;
//                             return !1;
//                         }
//                     }
//             }
//             return !0;
//         };
//         t.prototype.jiancha_youxi_shifou_bei_kazhu = function () {
//             this.isGameStuck = this._jiancha_youxi_shifou_bei_kazhu();
//             if (this.isGameStuck) {
//                 this.tipsCD = AL_GAME_HUA_GameConst.GameConst.getInstance().tips_duration;
//             }
//         };
//         t.prototype.shou_yidong_dongzuo = function (e, t) {
//             var n = this.node_layer_1_finger;
//             n.active = !0;
//             n.setPosition(e);
//             n.stopAllActions();
//             cc.tween(n)
//                 .to(0.1, {
//                     scale: 0.8
//                 })
//                 .to(0.85, {
//                     position: cc.v3(t)
//                 })
//                 .to(0.1, {
//                     scale: 1
//                 })
//                 .to(0.85, {
//                     position: cc.v3(e)
//                 })
//                 .union()
//                 .repeatForever()
//                 .start();
//         };
//         t.prototype.jiancha_wangge_kong_zhuangtai = function (e, t) {
//             return (
//                 e.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL &&
//                 3 == e.huoqu_wangge_kong_shuliang(t) &&
//                 (e.qingkong_layer(t), (this.tipsDuration = 0), (this.guideDuration = 0), !0)
//             );
//         };
//         t.prototype.jiancha_dange_gezi_zhuangtai = function (e) {
//             if (e.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                 var t = 0;
//                 for (var n = e.singlePos.length - 1; n >= 0; n--) {
//                     var o = e.singlePos[n];
//                     0 == t && o.showType != AL_GAME_HUA_Define.Define.ElementShowType.ACTIVE
//                         ? o.chuli_jianxian_zhanshi()
//                         : 1 == t
//                         ? o.showType == AL_GAME_HUA_Define.Define.ElementShowType.ACTIVE
//                             ? o.chuli_huidu_danru()
//                             : o.showType == AL_GAME_HUA_Define.Define.ElementShowType.HIDE && o.chuli_yincang_zhanshi()
//                         : 2 == t && o.showType == AL_GAME_HUA_Define.Define.ElementShowType.GRAY && o.chuli_yincang_danchu();
//                     t++;
//                 }
//             }
//         };
//         t.prototype.jiancha_gezi_shifou_wancheng = function (e) {
//             var t = this;
//             if (e.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                 return !1;
//             }
//             if (e.huoqu_wangge_zhuangtai().isComplete) {
//                 var n = e.huoqu_yuansiu_b_layer();
//                 e.bianli_layer_list(function (e) {
//                     if (-1 != t.guideGroup.indexOf(e)) {
//                         t.yichu_yindao();
//                     }
//                     t.yichu_yuansu(e);
//                 });
//                 e.isAnimating = !0;
//                 this.chooseElement.yidong_dao_weizhi().then(function () {
//                     var o = !1;
//                     n.forEach(function (t) {
//                         t.chuli_pengzhuang_xiaohuo(function () {
//                             if (!o) {
//                                 e.chuangjian_pengzhuang_xiaoguo(t.idx);
//                                 o = !0;
//                             }
//                         });
//                     });
//                     e.isAnimating = !1;
//                     e.qingkong_layer();
//                     t.chuli_crash(e.node);
//                 });
//                 AL_GAME_HUA_Instance.Instance.Game.gameUI.popNum++;
//                 if (this.levelGuide >= 0) {
//                     this.levelGuide++;
//                     this.jiancha_yindao();
//                 }
//                 return AL_GAME_HUA_Instance.Instance.Game.gameState != AL_GAME_HUA_Define.Define.GameState.WIN;
//             }
//             if (this.levelGuide >= 0) {
//                 this.node_layer_1_finger.active = !1;
//             }
//             return !1;
//         };
//         t.prototype.jiancha_suoyou_gezi_shifou_wancheng = function () {
//             return 0 == this.elements.length && (AL_GAME_HUA_Instance.Instance.Game.chuli_youxi_shengli(), !0);
//         };
//         t.prototype.chuli_crash = function (e) {
//             "tt" == ailin_sdk_manager.getSysPlatformName()
//                 ? AL_GAME_HUA_Common.Common.vibrate(!1)
//                 : "wx" == ailin_sdk_manager.getSysPlatformName()
//                 ? AL_GAME_HUA_Common.Common.vibrate(!0)
//                 : AL_GAME_HUA_Common.Common.vibrate(!1);
//             this.enabledGuide = !0;
//             var t =
//                 Math.min(5, Math.floor(AL_GAME_HUA_Instance.Instance.Game.gameUI.comboCount / 3) + 1) *
//                 (AL_GAME_HUA_GameData.GameData.getInstance().useStarEnter ? 2 : 1);
//             AL_GAME_HUA_Instance.Instance.Game.gameUI.chuangjian_xingxing(e, t);
//             AL_GAME_HUA_Instance.Instance.Game.gameUI.xianshi_combo(e);
//             if (!this.jiancha_suoyou_gezi_shifou_wancheng()) {
//                 this.tipsDuration = 0;
//                 this.guideDuration = 0;
//                 this.yincang_daoju_tishi();
//                 this.jiesuo_wangge();
//             }
//         };
//         t.prototype.jiesuo_wangge = function () {
//             if (0 != this.lock_lattice.length) {
//                 var e = this.lock_lattice[0];
//                 if (e.shifou_suoding) {
//                     e.chuli_jiesuo();
//                     if (!e.shifou_suoding) {
//                         this.lock_lattice.shift();
//                     }
//                 }
//             }
//         };
//         t.prototype.yichu_yuansu = function (e) {
//             this.elements.remove(e);
//             if (e.idx in this.map_element_list) {
//                 this.map_element_list[e.idx].remove(e);
//                 if (0 == this.map_element_list[e.idx].length) {
//                     delete this.map_element_list[e.idx];
//                 }
//             }
//             this.shuaxin_jindu();
//         };
//         t.prototype.chuli_tishi_luoji = function () {
//             return __awaiter(this, void 0, void 0, function () {
//                 var e;
//                 var t;
//                 var n;
//                 var o;
//                 var i;
//                 var r;
//                 var a;
//                 var s;
//                 var u;
//                 var p;
//                 var f;
//                 var h;
//                 var _;
//                 var P;
//                 var g;
//                 var y;
//                 var m;
//                 var v;
//                 var D = this;
//                 return __generator(this, function (c) {
//                     switch (c.label) {
//                         case 0:
//                             for (e = {}, P = 0; P < this.array_lattice_list.length; P++) {
//                                 (t = this.array_lattice_list[P]).type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
//                                     ? t.bianli_layer_list(function (t) {
//                                           if (t.idx in e == 0) {
//                                               e[t.idx] = [];
//                                           }
//                                           e[t.idx].push(t);
//                                       })
//                                     : t.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
//                                       (n = t.huoqu_single_yuansu()) &&
//                                       (n.idx in e == 0 && (e[n.idx] = []), e[n.idx].push(n));
//                             }
//                             for (a in ((o = []), (i = []), (r = []), e))
//                                 e[a].length >= 3
//                                     ? o.push(a)
//                                     : 2 == e[a].length
//                                     ? i.push(a)
//                                     : 1 == e[a].length && r.push(a);
//                             if (0 == (s = __spreadArrays(o.upset(), i.upset(), r.upset())).length) {
//                                 console.error("未能找到1组元素");
//                                 return [2];
//                             }
//                             if ((u = e[s[0]]).length < 3) {
//                                 p = u[0].idx;
//                                 f = this.map_element_list[p];
//                                 for (
//                                     P = 0;
//                                     P < f.length && ((h = f[P]), -1 == u.indexOf(h) && u.push(h), !(u.length >= 3));
//                                     P++
//                                 ) {}
//                             }
//                             for (_ = [], P = 0; P < u.length && (_.push(u[P]), !(_.length >= 3)); P++) {}
//                             g = AL_GAME_HUA_Define.Define.LATTICE_POS;
//                             _ = _.sort(function (e, t) {
//                                 return e.node.x - t.node.x;
//                             });
//                             y = 0;
//                             m = [];
//                             v = !1;
//                             _.forEach(function (e) {
//                                 var t = e.belone;
//                                 t.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
//                                     ? (t.yichu_yuansu(e, e.layer), D.jiancha_wangge_kong_zhuangtai(t, e.layer))
//                                     : t.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
//                                       (t.yichu_yuansu_from_single(), D.jiancha_dange_gezi_zhuangtai(t));
//                                 D.yichu_yuansu(e);
//                                 if (-1 != D.guideGroup.indexOf(e)) {
//                                     D.yichu_yindao();
//                                 }
//                                 m.push(
//                                     e.chuli_yidong_pengzhuang_xiaohuo(
//                                         g[y].mul(1.5),
//                                         AL_GAME_HUA_Define.Define.LATTICE_ANGLE[y],
//                                         function () {
//                                             if (!v) {
//                                                 D.chuangjian_yidong_crash_texiao(g[1].mul(1.5).add(cc.v2(0, 180)), e.idx, 1.6);
//                                                 v = !0;
//                                             }
//                                         }
//                                     )
//                                 );
//                                 y++;
//                             });
//                             this.tipsDuration = 0;
//                             this.guideDuration = 0;
//                             return [4, Promise.all(m).then(function () {})];
//                         case 1:
//                             c.sent();
//                             this.chuli_crash(this.node);
//                             this.jiancha_youxi_shifou_bei_kazhu();
//                             return [2];
//                     }
//                 });
//             });
//         };
//         t.prototype.chuangjian_yidong_crash_texiao = function (e, t, n) {
//             var o = Math.get_random_int(0, 3);
//             var i = AL_GAME_HUA_GamePool.GamePool.Instance.get("crashEffect" + o);
//             i.zIndex = 1020;
//             i.scale = n || 1;
//             i.getComponent(AL_GAME_HUA_CrashEffect.default).refresh(t);
//             this.node.addChild(i);
//             i.setPosition(e);
//             this.scheduleOnce(function () {
//                 AL_GAME_HUA_GamePool.GamePool.Instance.put(i);
//             }, 2);
//         };
//         t.prototype.shuaxin_daoju_he_yuansu_zhuangtai = function () {
//             this.yichu_yindao();
//             var e = Object.keys(this.map_element_list).map(function (e) {
//                 return Number(e);
//             });
//             var t = e.length;
//             var n = this.elements.length;
//             this.array_lattice_list.forEach(function (e) {
//                 e.reset();
//             });
//             for (var o = 0; o < this.elements.length; o++) {
//                 AL_GAME_HUA_GamePool.GamePool.Instance.put(this.elements[o].node);
//             }
//             this.elements = [];
//             this.map_element_list = [];
//             if (
//                 AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.CHALLENGE ||
//                 AL_GAME_HUA_Common.Common.shifou_keyi_kaiqi_tiaozhan_guanqia()
//             ) {
//                 this.recordConf = {
//                     displaceCount: 0,
//                     displaceElement: 0,
//                     layerDisRate: {},
//                     layerDisCount: {},
//                     displaceLayers: 0,
//                     displaceLayerFb: {},
//                     layerInfos: []
//                 };
//                 this.elementAllocator = new AL_GAME_HUA_ElementAllocator.ElementAllocator({
//                     icons: e,
//                     type: t,
//                     count: n
//                 });
//                 var i = this.huoqu_youxiao_de_wangge();
//                 var r = i.normals;
//                 var a = i.singles;
//                 var s = Math.ceil(n / (3 * 0.7 * r.length));
//                 var c = Math.floor((s / 3) * 2);
//                 var l = Math.floor(s / 3);
//                 if (a.length > 0) {
//                     this.tianchong_dange_ceng(a, r.length + a.length);
//                 }
//                 for (var u = 0; this.elementAllocator.iconsLenght > 0; ) {
//                     this.tianchong_wangge_ceng({
//                         layer: u,
//                         normals: r.slice().upset(),
//                         empty: this.levelData.Empty,
//                         space: u <= l ? 0 : u <= c ? 1 : 2
//                     });
//                     u++;
//                 }
//                 this.displaceProducts = [];
//                 for (o = 0; o < u; o++) {
//                     this.zhixing_cengji_weiyi_caozuo({
//                         layer: o,
//                         normals: r,
//                         space: o <= l ? 0 : o <= c ? 1 : 2
//                     });
//                 }
//                 var h = [];
//                 for (o = 0; o < u; o++) {
//                     var _ = this.jisuan_cengji_xinxi(o, r, a);
//                     h.push(_);
//                 }
//                 this.recordConf.layerInfos = h;
//             } else {
//                 if (
//                     AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.NORMAL ||
//                     AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.SPECIAL
//                 ) {
//                     this.elementAllocator = new AL_GAME_HUA_ElementAllocator.ElementAllocator({
//                         icons: e,
//                         type: t,
//                         count: n
//                     });
//                     var P = this.huoqu_youxiao_de_wangge();
//                     r = P.normals;
//                     a = P.singles;
//                     s = Math.ceil(n / (3 * 0.7 * r.length));
//                     c = Math.floor((s / 3) * 2);
//                     l = Math.floor(s / 3);
//                     if (a.length > 0) {
//                         this.tianchong_dange_ceng(a, r.length + a.length);
//                     }
//                     for (u = 0; this.elementAllocator.iconsLenght > 0; ) {
//                         this.tianchong_wangge_ceng({
//                             layer: u,
//                             normals: r.slice().upset(),
//                             empty: this.levelData.Empty,
//                             space: u <= l ? 0 : u <= c ? 1 : 2
//                         });
//                         u++;
//                     }
//                 }
//             }
//             this.elements.forEach(function (e) {
//                 e.shezhi_tubiao();
//                 e.chuli_chuangjian_zhanshi();
//             });
//             this.yincang_daoju_tishi();
//             this.jiancha_youxi_shifou_bei_kazhu();
//             AL_GAME_HUA_Common.Common.bofang_yinxiao("stick", this);
//         };
//         t.prototype.daoju_qihuan = function () {
//             this.yichu_yindao();
//             AL_GAME_HUA_Common.Common.bofang_yinxiao("refresh", this);
//             var e = [];
//             var t = new Set();
//             for (var n = 0; n < this.array_lattice_list.length; n++) {
//                 if ((y = this.array_lattice_list[n]).type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                     if (y.isVideoLock) {
//                         continue;
//                     }
//                     y.bianli_layer_list(function (n) {
//                         e.push(n);
//                         t.add(n.idx);
//                     });
//                 } else {
//                     if (y.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                         var o = y.huoqu_single_yuansu();
//                         if (o) {
//                             e.push(o);
//                             t.add(o.idx);
//                         }
//                     }
//                 }
//             }
//             var i = Array.from(t);
//             if (this.lastIdx > 0 && i.length > 1) {
//                 i.remove(this.lastIdx);
//             }
//             var r = i.huoqu_shuzu_zhong_suiji_yige_yuansu();
//             this.lastIdx = r;
//             var a = [];
//             var s = 0;
//             var c = function (e) {
//                 var t = u.array_lattice_list[e];
//                 if (t.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                     if (t.isVideoLock) {
//                         return "continue";
//                     }
//                     var n = 0;
//                     var o = t.huoqu_layer_shuliang();
//                     for (var i = t.curLayer; i < o; i++) {
//                         a[n] || (a[n] = []);
//                         t.bianli_layer_list(function (e) {
//                             if (e.idx != n) {
//                                 a[n].push(e);
//                                 s++;
//                             }
//                         }, i);
//                         n++;
//                     }
//                 } else {
//                     if (t.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                         var r = 0;
//                         for (var c = t.singlePos.length - 1; c >= 0; c--) {
//                             if (!a[r]) {
//                                 a[r] = [];
//                             }
//                             var l = t.singlePos[c];
//                             if (l.idx != r) {
//                                 a[r].push(l);
//                                 s++;
//                             }
//                             r++;
//                         }
//                     }
//                 }
//             };
//             var u = this;
//             for (n = 0; n < this.array_lattice_list.length; n++) {
//                 c(n);
//             }
//             var p = Math.min(9, s);
//             var h = [];
//             a.forEach(function (e) {
//                 h = __spreadArrays(h, e.upset());
//             });
//             for (var _ = []; _.length < p; ) {
//                 var P = h[0].idx;
//                 var g = this.map_element_list[P].slice();
//                 for (n = 0; n < 3; n++) {
//                     var y;
//                     var m = g[n];
//                     h.remove(m);
//                     _.push(m);
//                     if ((y = m.belone).type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                         if (m.layer != y.curLayer) {
//                             for (var v = 0; v < h.length; v++) {
//                                 if (h[v].idx != P) {
//                                     var D = h[v];
//                                     var L = {
//                                         belone: m.belone,
//                                         posIdx: m.posIdx,
//                                         layer: m.layer
//                                     };
//                                     m.belone.yichu_yuansu(m, m.layer);
//                                     D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
//                                         ? (D.belone.yichu_yuansu(D, D.layer),
//                                           D.belone.tianjia_yuansu_dao(m, D.posIdx, D.layer, !0))
//                                         : D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
//                                           (D.belone.yichu_yuansu_from_single(D), D.belone.tianjia_single_dao(m, D.layer, !0));
//                                     L.belone.tianjia_yuansu_dao(D, L.posIdx, L.layer, !0);
//                                     h.remove(D);
//                                     break;
//                                 }
//                             }
//                         }
//                     } else {
//                         if (y.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE && 0 != m.layer) {
//                             for (var b = 0; b < h.length; b++) {
//                                 if (h[b].idx != P) {
//                                     D = h[b];
//                                     L = {
//                                         belone: m.belone,
//                                         posIdx: m.posIdx,
//                                         layer: m.layer
//                                     };
//                                     m.belone.yichu_yuansu_from_single(m);
//                                     D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
//                                         ? (D.belone.yichu_yuansu(D, D.layer),
//                                           D.belone.tianjia_yuansu_dao(m, D.posIdx, D.layer, !0))
//                                         : D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
//                                           (D.belone.yichu_yuansu_from_single(D), D.belone.tianjia_single_dao(m, D.layer, !0));
//                                     L.belone.tianjia_single_dao(D, L.layer, !0);
//                                     h.remove(D);
//                                     break;
//                                 }
//                             }
//                         }
//                     }
//                     m.chuli_zhuangtai_gaibian(r);
//                     this.map_element_list[P].remove(m);
//                     this.map_element_list[r].unshift(m);
//                 }
//             }
//             this.yincang_daoju_tishi();
//             this.jiancha_youxi_shifou_bei_kazhu();
//         };
//         t.prototype.shijian_daoju_xiaoguo_luoji = function () {
//             return __awaiter(this, void 0, void 0, function () {
//                 return __generator(this, function () {
//                     AL_GAME_HUA_Instance.Instance.Game.isTimePause = !0;
//                     AL_GAME_HUA_Instance.Instance.Game.gameUI.iceNode.active = !0;
//                     AL_GAME_HUA_Instance.Instance.Game.gameUI.iceNode.opacity = 0;
//                     AL_GAME_HUA_Instance.Instance.Game.gameUI.iceNode.stopAllActions();
//                     cc.tween(AL_GAME_HUA_Instance.Instance.Game.gameUI.iceNode)
//                         .to(0.5, {
//                             opacity: 255
//                         })
//                         .start();
//                     AL_GAME_HUA_Common.Common.bofang_yinxiao("freeze", this);
//                     AL_GAME_HUA_Instance.Instance.Game.gameUI.zhanting_combo();
//                     this.scheduleOnce(function () {
//                         AL_GAME_HUA_Instance.Instance.Game.isTimePause = !1;
//                         AL_GAME_HUA_Instance.Instance.Game.gameUI.jixu_combo();
//                         cc.tween(AL_GAME_HUA_Instance.Instance.Game.gameUI.iceNode)
//                             .to(0.5, {
//                                 opacity: 0
//                             })
//                             .call(function () {
//                                 AL_GAME_HUA_Instance.Instance.Game.gameUI.iceNode.active = !1;
//                             })
//                             .start();
//                     }, AL_GAME_HUA_GameConst.GameConst.getInstance().time_prop_duration);
//                     return [2];
//                 });
//             });
//         };
//         t.prototype.shezhi_ditu_chicun = function (e, t) {
//             cc.winSize.width;
//             cc.winSize.height;
//             AL_GAME_HUA_Define.Define.Margin.bottom = 180;
//             AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.CHALLENGE
//                 ? (AL_GAME_HUA_Define.Define.Margin.top = 160)
//                 : (AL_GAME_HUA_Define.Define.Margin.top = 120);
//             var n = AL_GAME_HUA_Define.Define.getWidth() / t;
//             var o = AL_GAME_HUA_Define.Define.getHeight() / e;
//             AL_GAME_HUA_Define.Define.LATTICE_WIDTH = Math.max(n, AL_GAME_HUA_Define.Define.MIN_LATTICE_WIDTH);
//             AL_GAME_HUA_Define.Define.LATTICE_HEIGHT = Math.clamp(
//                 o,
//                 AL_GAME_HUA_Define.Define.MIN_lATTICE_HEIGHT,
//                 AL_GAME_HUA_Define.Define.MAX_LATTICE_HEIGHT
//             );
//             var i = AL_GAME_HUA_Define.Define.getWidth() / (t * AL_GAME_HUA_Define.Define.LATTICE_WIDTH);
//             var r = AL_GAME_HUA_Define.Define.getHeight() / (e * AL_GAME_HUA_Define.Define.LATTICE_HEIGHT);
//             this.mapSize = cc.size(
//                 t * AL_GAME_HUA_Define.Define.LATTICE_WIDTH,
//                 e * AL_GAME_HUA_Define.Define.LATTICE_HEIGHT
//             );
//             this.node.scale = Math.min(i, r);
//             this.node.x = 0;
//             this.node.y = AL_GAME_HUA_Define.Define.getCenter();
//             console.log(
//                 "LATTICE_WIDTH:",
//                 AL_GAME_HUA_Define.Define.LATTICE_WIDTH,
//                 "LATTICE_HEIGHT:",
//                 AL_GAME_HUA_Define.Define.LATTICE_HEIGHT,
//                 "SCALE:",
//                 this.node.scale
//             );
//         };
//         t.prototype.chuangjian_ditu_by_leixing = function (e, t, n) {
//             var o;
//             var i = this;
//             if (1 == e) {
//                 var r = Math.ceil(t / 3);
//                 var a = parseInt("100" + r);
//                 AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.NORMAL
//                     ? (o = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_wangge_peizhi_by_id(a))
//                     : AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.CHALLENGE
//                     ? (o = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_tiaozhan_guanqia_peizhi_by_id(
//                           a,
//                           AL_GAME_HUA_Instance.Instance.ChallengeLevel
//                       ))
//                     : AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.SPECIAL &&
//                       (o = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_teshu_guanqia_peizhi_by_id(a));
//             } else {
//                 AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.NORMAL
//                     ? (o = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_wangge_peizhi_by_id(e))
//                     : AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.CHALLENGE
//                     ? (o = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_tiaozhan_guanqia_peizhi_by_id(
//                           e,
//                           AL_GAME_HUA_Instance.Instance.ChallengeLevel
//                       ))
//                     : AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.SPECIAL &&
//                       (o = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_teshu_guanqia_peizhi_by_id(e));
//             }
//             console.log("latticeConfig:", JSON.stringify(o));
//             var s = o.list;
//             var c = o.row;
//             var l = o.col;
//             this.latticeConfig = o;
//             s = s.slice();
//             this.shezhi_ditu_chicun(c, l);
//             var u = [];
//             s.forEach(function (e, t) {
//                 if (0 == e) {
//                     u.push(t);
//                 }
//             });
//             if (n > 0) {
//                 u.huoqu_shuzu_suiji_zhiding_shuliang_buchongfu_yuansu(n).forEach(function (e) {
//                     s[e] = AL_GAME_HUA_Define.Define.LatticeType.LOCK;
//                 });
//             }
//             var f = cc.v2(-this.mapSize.width / 2, this.mapSize.height / 2);
//             for (var h = 0; h < l; h++) {
//                 this.map_lattice_list[h] = [];
//                 for (var g = 0; g < c; g++) {
//                     var y = s[h * c + g];
//                     if (void 0 === y) {
//                         y = AL_GAME_HUA_Define.Define.LatticeType.NULL;
//                     }
//                     if (
//                         y == AL_GAME_HUA_Define.Define.LatticeType.VIDEO &&
//                         AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() <
//                             AL_GAME_HUA_GameConst.GameConst.getInstance().video_lattice_unlock
//                     ) {
//                         y = AL_GAME_HUA_Define.Define.LatticeType.NORMAL;
//                     }
//                     (C = this.chuangjian_wangge_duixiang()).init({
//                         type: y,
//                         onLatticeUnlock: function () {
//                             i.yincang_daoju_tishi();
//                             i.jiancha_youxi_shifou_bei_kazhu();
//                         }
//                     });
//                     if (y == AL_GAME_HUA_Define.Define.LatticeType.LOCK) {
//                         this.lock_lattice.push(C);
//                     }
//                     var v =
//                         f.x + h * AL_GAME_HUA_Define.Define.LATTICE_WIDTH + AL_GAME_HUA_Define.Define.LATTICE_WIDTH / 2;
//                     var D =
//                         f.y - g * AL_GAME_HUA_Define.Define.LATTICE_HEIGHT - AL_GAME_HUA_Define.Define.LATTICE_HEIGHT / 2;
//                     C.node.setPosition(v, D);
//                     this.array_lattice_list.push(C);
//                     this.map_lattice_list[h][g] = C;
//                     C.row = g;
//                     C.col = h;
//                     C.node.zIndex = 10 - g;
//                 }
//             }
//             if (this.lock_lattice.length > 0) {
//                 this.lock_lattice = this.lock_lattice.upset();
//             }
//             for (g = 0; g < c; g++) {
//                 var L = [];
//                 var b = 0;
//                 for (h = 0; h < l; h++) {
//                     var C;
//                     (C = this.map_lattice_list[h][g]).type != AL_GAME_HUA_Define.Define.LatticeType.NULL
//                         ? C.type != AL_GAME_HUA_Define.Define.LatticeType.SINGLE
//                             ? (L[b] || (L[b] = []), L[b].push(C))
//                             : (((S = this.chuangjian_guizi()).x = C.node.x),
//                               (S.y = C.node.y - 90),
//                               (S.width = (AL_GAME_HUA_Define.Define.LATTICE_WIDTH / 3) * 2),
//                               (b = L.length))
//                         : (b = L.length);
//                 }
//                 for (var H = 0; H < L.length; H++) {
//                     var I = L[H];
//                     if (0 != I.length) {
//                         var S = this.chuangjian_guizi();
//                         for (var w = ((v = 0), 0); w < I.length; w++) {
//                             v += I[w].node.x;
//                         }
//                         v /= I.length;
//                         D = I[0].node.y - 90;
//                         S.setPosition(v, D);
//                         var Y = I.length * AL_GAME_HUA_Define.Define.LATTICE_WIDTH;
//                         S.width = Y;
//                     }
//                 }
//             }
//         };
//         t.prototype.chuangjian_guizi = function () {
//             var e = AL_GAME_HUA_GamePool.GamePool.Instance.get("guizi");
//             this.node_layer_lattice.addChild(e);
//             return e;
//         };
//         t.prototype.yibu_jiazai_yuansu = function () {
//             return __awaiter(this, void 0, Promise, function () {
//                 var e = this;
//                 return __generator(this, function () {
//                     return [
//                         2,
//                         new Promise(function (t, n) {
//                             Log.ts("@@@加载所有元素");
//                             Log.ts("@@@前两层元素加载");
//                             var o = new Set();
//                             var i = {};
//                             var r = new Set();
//                             var a = new Set();
//                             for (var l = 0; l < e.array_lattice_list.length; l++) {
//                                 var u = e.array_lattice_list[l];
//                                 if (u.type != AL_GAME_HUA_Define.Define.LatticeType.NULL) {
//                                     u.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
//                                         ? u.bianli_yuansu_list(function (e, t, n) {
//                                               if (e.idx in i == 0) {
//                                                   i[e.idx] = [];
//                                               }
//                                               i[e.idx].push(e);
//                                               o.add(e.idx);
//                                               n < 2 ? r.add(e.idx) : a.add(e.idx);
//                                           })
//                                         : u.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
//                                           u.singlePos.forEach(function (e) {
//                                               if (e.idx in i == 0) {
//                                                   i[e.idx] = [];
//                                               }
//                                               i[e.idx].push(e);
//                                               o.add(e.idx);
//                                               r.add(e.idx);
//                                           });
//                                 }
//                             }
//                             var p = function (t) {
//                                 return new Promise(function (n, o) {
//                                     return __awaiter(e, void 0, void 0, function () {
//                                         var e;
//                                         return __generator(this, function (r) {
//                                             switch (r.label) {
//                                                 case 0:
//                                                     return [
//                                                         4,
//                                                         AL_GAME_HUA_ElementConfig.ElementConfig.getInstance().jiazai_tubiao_icon(t)
//                                                     ];
//                                                 case 1:
//                                                     return (e = r.sent())
//                                                         ? (i[t].forEach(function (n) {
//                                                               if (cc.isValid(n) && n.idx == t) {
//                                                                   n.shezhi_sprite_frame(e);
//                                                               }
//                                                           }),
//                                                           [2, n()])
//                                                         : [2, o()];
//                                             }
//                                         });
//                                     });
//                                 });
//                             };
//                             var f = [];
//                             r.forEach(function (e) {
//                                 f.push(p(e));
//                             });
//                             Promise.all(f)
//                                 .then(function () {
//                                     return __awaiter(e, void 0, void 0, function () {
//                                         var e;
//                                         var n = this;
//                                         return __generator(this, function () {
//                                             Log.te("@@@前两层元素加载");
//                                             t();
//                                             e = 0;
//                                             a.forEach(function (t) {
//                                                 return __awaiter(n, void 0, void 0, function () {
//                                                     return __generator(this, function (n) {
//                                                         switch (n.label) {
//                                                             case 0:
//                                                                 return [4, p(t)];
//                                                             case 1:
//                                                                 n.sent();
//                                                                 if (++e == a.size) {
//                                                                     Log.te("@@@加载所有元素");
//                                                                 }
//                                                                 return [2];
//                                                         }
//                                                     });
//                                                 });
//                                             });
//                                             return [2];
//                                         });
//                                     });
//                                 })
//                                 .catch(function () {
//                                     n();
//                                 });
//                         })
//                     ];
//                 });
//             });
//         };
//         t.prototype.xianshi_yuansu_list = function () {
//             var e = [];
//             for (var t = 0; t < this.elements.length; t++) {
//                 e.push(this.elements[t].chuli_chuangjian_zhanshi());
//             }
//             AL_GAME_HUA_Common.Common.bofang_yinxiao("stick", this);
//             return Promise.all(e).then(function () {});
//         };
//         t.prototype.shengcheng_yuansu = function () {
//             var e = this.levelData;
//             var t = (e.Lattce, e.Type);
//             var n = e.Number;
//             var o = e.Empty;
//             var i = this.latticeConfig;
//             var r = i.displaceBase;
//             var a = i.zhixing_cengji_weiyi_caozuo;
//             var s = i.displaceMax;
//             var c = i.increaseBase;
//             var l = i.increaseLayer;
//             var u = AL_GAME_HUA_ElementConfig.ElementConfig.getInstance().huoqu_tubiao_genju_dengji(t);
//             var f = this.huoqu_youxiao_de_wangge();
//             var g = f.normals;
//             var y = f.singles;
//             if (
//                 1 == AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() &&
//                 AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.NORMAL
//             ) {
//                 var v = [];
//                 for (var D = 0; D < 10; D++) {
//                     v.push(u[D]);
//                 }
//                 var L = v.huoqu_shuzu_suiji_zhiding_shuliang_buchongfu_yuansu(2);
//                 g[0].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(L[0]), 0, 0);
//                 g[0].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(L[0]), 1, 0);
//                 g[1].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(L[1]), 0, 0);
//                 g[1].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(L[1]), 1, 0);
//                 g[2].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(L[1]), 2, 0);
//                 return void g[3].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(L[0]), 1, 0);
//             }
//             this.elementAllocator = new AL_GAME_HUA_ElementAllocator.ElementAllocator({
//                 icons: u,
//                 type: t,
//                 count: n
//             });
//             var b = Math.ceil(n / (3 * 0.7 * g.length));
//             var H = Math.floor((b / 3) * 2);
//             var I = Math.floor(b / 3);
//             var S = Math.get_random(r[0], r[1]);
//             var w = Math.get_random(a[0], a[1]);
//             var Y = Math.get_random(c[0], c[1]);
//             var E = (Math.get_random(l[0], l[1]), Math.max(s[0], s[1]));
//             var A = AL_GAME_HUA_GameData.GameData.getInstance().huoqu_dangqian_nandu();
//             var T =
//                 AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.SPECIAL
//                     ? this.levelData.ID
//                     : AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia();
//             var R = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_nandu_by_guanqia(T);
//             var G = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_guanqia_increase(T);
//             var N = A + R;
//             S = Math.min(E, G * S + N * Y);
//             w = Math.min(E, G * w + N * Y);
//             this.difficultConf = {
//                 displaceBase: S,
//                 zhixing_cengji_weiyi_caozuo: w,
//                 displaceMax: E
//             };
//             this.recordConf = {
//                 displaceCount: 0,
//                 displaceElement: 0,
//                 layerDisRate: {},
//                 layerDisCount: {},
//                 displaceLayers: 0,
//                 displaceLayerFb: {},
//                 layerInfos: []
//             };
//             if (y.length > 0) {
//                 this.tianchong_dange_ceng(y, g.length + y.length);
//             }
//             for (var k = 0; this.elementAllocator.iconsLenght > 0; ) {
//                 this.tianchong_wangge_ceng({
//                     layer: k,
//                     normals: g.slice().upset(),
//                     empty: o,
//                     space: k <= I ? 0 : k <= H ? 1 : 2
//                 });
//                 k++;
//             }
//             if (AL_GAME_HUA_Instance.Instance.LevelType == AL_GAME_HUA_Define.Define.LevelType.NORMAL) {
//                 if (
//                     AL_GAME_HUA_GameConst.GameConst.getInstance().lv2hard_enabled &&
//                     AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() ==
//                         AL_GAME_HUA_GameConst.GameConst.getInstance().lv2hard_level
//                 ) {
//                 } else {
//                     if (
//                         AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() <=
//                         AL_GAME_HUA_GameConst.GameConst.getInstance().displaceLevel
//                     ) {
//                         return;
//                     }
//                 }
//             }
//             var O = k;
//             this.totalLayer = O;
//             this.displaceProducts = [];
//             for (D = 0; D < O; D++) {
//                 this.zhixing_cengji_weiyi_caozuo({
//                     layer: D,
//                     normals: g,
//                     space: D <= I ? 0 : D <= H ? 1 : 2
//                 });
//             }
//             var M = [];
//             for (D = 0; D < O; D++) {
//                 var B = this.jisuan_cengji_xinxi(D, g, y);
//                 M.push(B);
//             }
//             this.recordConf.layerInfos = M;
//         };
//         t.prototype.jisuan_cengji_xinxi = function (e, t, n) {
//             var o = 3 * t.length + n.length;
//             var i = __spreadArrays(t, n);
//             var r = 0;
//             var a = 0;
//             var s = 0;
//             var c = {};
//             var u = 0;
//             for (var p = 0; p < i.length; p++) {
//                 var f = i[p];
//                 var h = -1 == e ? f.curLayer : e;
//                 if (f.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                     if (h >= f.singlePos.length) {
//                         continue;
//                     }
//                     if ((D = f.singlePos[f.singlePos.length - e - 1])) {
//                         r++;
//                         if (D.idx in c == 0) {
//                             c[D.idx] = 0;
//                         }
//                         c[D.idx]++;
//                     }
//                 } else {
//                     if (f.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                         f.bianli_layer_list(function (e) {
//                             r++;
//                             if (e.idx in c == 0) {
//                                 c[e.idx] = 0;
//                             }
//                             c[e.idx]++;
//                         }, h);
//                     }
//                 }
//             }
//             var _ = o - r;
//             var P = _ / o;
//             var g = Object.keys(c);
//             for (var y in c)
//                 if (c[y] >= 3) {
//                     a += 3 * Math.floor(c[y] / 3);
//                 }
//             var m = a / o;
//             for (p = 0; p < i.length; p++) {
//                 f = i[p];
//                 var v = -1 == e ? f.curLayer + 1 : e + 1;
//                 if (f.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
//                     if (v >= f.singlePos.length) {
//                         continue;
//                     }
//                     var D = f.singlePos[f.singlePos.length - v - 1];
//                     if (g.indexOf(String(D.idx)) >= 0) {
//                         s++;
//                     }
//                     u++;
//                 } else {
//                     if (f.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
//                         f.bianli_layer_list(function (e) {
//                             if (g.indexOf(String(e.idx)) >= 0) {
//                                 s++;
//                             }
//                             u++;
//                         }, v);
//                     }
//                 }
//             }
//             return {
//                 layer: e,
//                 empty: _,
//                 emptyRate: P,
//                 crashCount: a,
//                 crashRate: m,
//                 nextConnectCount: s,
//                 nextConnectRate: 0 == u ? 0 : s / u
//             };
//         };
//         t.prototype.shuaxin_jindu = function () {
//             var e = 1 - this.elements.length / this.levelData.Number;
//             AL_GAME_HUA_Instance.Instance.Game.gameUI.shuaxin_guanqia_jindu(e);
//         };
//         t.prototype.zhixing_cengji_weiyi_caozuo = function (e) {
//             var t = e.layer;
//             var n = e.normals;
//             var o = this.difficultConf;
//             var i = o.displaceBase;
//             var r = o.zhixing_cengji_weiyi_caozuo;
//             var a = o.displaceMax;
//             this.recordConf.layerDisCount[t] = 0;
//             var s = Math.min(i + t * r, a);
//             this.recordConf.layerDisRate[t] = s;
//             for (var c = 0; c < n.length; c++) {
//                 var u = n[c];
//                 var p = u.huoqu_wangge_kong_shuliang(t);
//                 if (3 != p) {
//                     var f = u.huoqu_layer_suoyin(t);
//                     if (!(this.displaceProducts.indexOf(f) >= 0) && Math.random() < s / 100) {
//                         var d = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_displace_jiange(e.space);
//                         for (var h = Math.min(t + d, this.totalLayer); h > t; ) {
//                             var _ = [];
//                             var g = [];
//                             var y = [];
//                             for (var m = 0; m < n.length; m++) {
//                                 var v = n[m].huoqu_layer_suoyin(h);
//                                 if (!(this.displaceProducts.indexOf(v) >= 0)) {
//                                     var D = n[m].huoqu_wangge_kong_shuliang(h);
//                                     if (0 == D) {
//                                         _.push(n[m]);
//                                     }
//                                     if (1 == D) {
//                                         g.push(n[m]);
//                                     }
//                                     if (2 == D) {
//                                         y.push(n[m]);
//                                     }
//                                 }
//                             }
//                             var L = [_, g, y];
//                             var b = [];
//                             b = __spreadArrays(L[p]);
//                             L.removeAt(p);
//                             if ((b = __spreadArrays(b, __spreadArrays(L[0], L[1]).upset())).length > 0) {
//                                 var C = b[0];
//                                 v = C.huoqu_layer_suoyin(h);
//                                 this.displaceProducts.push(v);
//                                 var H = u.huoqu_yuansiu_b_layer(t).slice();
//                                 var I = C.huoqu_yuansiu_b_layer(h).slice();
//                                 for (var S = 0; S < H.length; S++) {
//                                     H[S]
//                                         ? (this.recordConf.displaceElement++, C.tianjia_yuansu_dao(H[S], H[S].posIdx, h, !0))
//                                         : (C.huoqu_yuansiu_b_layer(h)[S] = null);
//                                 }
//                                 for (var w = 0; w < I.length; w++) {
//                                     I[w]
//                                         ? (this.recordConf.displaceElement++, u.tianjia_yuansu_dao(I[w], I[w].posIdx, t, !0))
//                                         : (u.huoqu_yuansiu_b_layer(t)[w] = null);
//                                 }
//                                 this.recordConf.layerDisCount[t]++;
//                                 this.recordConf.displaceCount++;
//                                 var Y = h - t;
//                                 this.recordConf.displaceLayers += Y;
//                                 if (Y in this.recordConf.displaceLayerFb == 0) {
//                                     this.recordConf.displaceLayerFb[Y] = 0;
//                                 }
//                                 this.recordConf.displaceLayerFb[Y]++;
//                                 break;
//                             }
//                             h--;
//                         }
//                     }
//                 }
//             }
//         };
//         t.prototype.tianchong_wangge_ceng = function (e) {
//             var t = e.normals;
//             var n = e.empty;
//             for (var o = (e.layer, 0); o < t.length; o++) {
//                 var i = t[o];
//                 this.tianchong_wangge(i, e.layer, e.space);
//             }
//             if (0 == e.layer) {
//                 var r = 0;
//                 var a = [];
//                 var s = [];
//                 var c = [];
//                 var u = [];
//                 for (o = 0; o < t.length; o++) {
//                     var p = (i = t[o]).huoqu_wangge_kong_shuliang(0);
//                     r += p;
//                     0 == p ? u.push(i) : 1 == p ? c.push(i) : 2 == p ? s.push(i) : a.push(i);
//                 }
//                 if (r < n) {
//                     var f = __spreadArrays(u.slice().upset(), c.slice().upset());
//                     for (var d = 0; r < n && f.length > 0; ) {
//                         var h = (i = f[d % f.length]).yichu_yuansu_suiji();
//                         h
//                             ? (this.elementAllocator.tianjia_tubiao(h.idx),
//                               AL_GAME_HUA_GamePool.GamePool.Instance.put(h.node),
//                               this.yichu_yuansu(h),
//                               r++,
//                               i.huoqu_wangge_kong_shuliang() >= 2 ? f.remove(i) : d++)
//                             : f.remove(i);
//                     }
//                 } else {
//                     if (r > n) {
//                         f = __spreadArrays(a.slice().upset(), s.slice().upset(), c.slice().upset());
//                         for (d = 0; r > n && ((i = f[d % f.length]), 0 != this.elementAllocator.iconsLenght); ) {
//                             this.changshi_qiangzhi_tianchong_wangge(i, e.layer) && r--;
//                             d++;
//                         }
//                     }
//                 }
//             }
//         };
//         t.prototype.tianchong_wangge = function (e, t, n) {
//             var o = this.levelData;
//             var i = o.Null0;
//             var r = o.Null1;
//             var a = o.Null2;
//             var s = o.Null3;
//             var c = [i[n], r[n], a[n]];
//             var l = this.elementAllocator;
//             var u = this.huoqu_jisuan_gailv_genju_liebiao(c);
//             if (0 == u) {
//                 if (Math.random() < s[n]) {
//                     var p = l.chazhao_liangge();
//                     for (var f = 0; f < p.length; f++) {
//                         var d = this.chuangjian_yuansu_duixiang(p[f]);
//                         e.charu_yuansu(d, t);
//                     }
//                 }
//                 for (; 0 != l.iconsLenght; ) {
//                     var h = e.huoqu_wangge_zhuangtai(t);
//                     var _ = h.total;
//                     var P = h.isDouble;
//                     var g = h.set;
//                     if (3 == _) {
//                         break;
//                     }
//                     if (1 == _ || 0 == _) {
//                         if ((y = l.chazhao_dange.apply(l, Array.from(g)))) {
//                             d = this.chuangjian_yuansu_duixiang(y);
//                             e.charu_yuansu(d, t);
//                         }
//                     } else {
//                         if (2 == _) {
//                             var y = void 0;
//                             if (P) {
//                                 var m = e.huoqu_yuansiu_b_layer(t);
//                                 var v = m[0] ? m[0].idx : m[1] ? m[1].idx : m[2].idx;
//                                 if ((y = l.chazhao_dange(v)) == v) {
//                                     l.tianjia_tubiao(v);
//                                     y = null;
//                                 }
//                             } else {
//                                 y = l.chazhao_dange.apply(l, Array.from(g));
//                             }
//                             if (y) {
//                                 d = this.chuangjian_yuansu_duixiang(y);
//                                 e.charu_yuansu(d, t);
//                             }
//                             break;
//                         }
//                     }
//                 }
//             } else {
//                 if (1 == u) {
//                     if (Math.random() < s[n]) {
//                         p = l.chazhao_liangge();
//                         for (f = 0; f < p.length; f++) {
//                             d = this.chuangjian_yuansu_duixiang(p[f]);
//                             e.charu_yuansu(d, t);
//                         }
//                     }
//                     for (; 0 != l.iconsLenght; ) {
//                         var D = e.huoqu_wangge_zhuangtai(t);
//                         _ = D.total;
//                         g = D.set;
//                         if (!(_ < 2)) {
//                             break;
//                         }
//                         if ((y = l.chazhao_dange.apply(l, Array.from(g)))) {
//                             d = this.chuangjian_yuansu_duixiang(y);
//                             e.charu_yuansu(d, t);
//                         }
//                     }
//                 } else {
//                     if (2 == u && (y = l.chazhao_dange(-1))) {
//                         d = this.chuangjian_yuansu_duixiang(y);
//                         e.charu_yuansu(d, t);
//                     }
//                 }
//             }
//         };
//         t.prototype.changshi_qiangzhi_tianchong_wangge = function (e, t) {
//             var n = e.huoqu_wangge_zhuangtai(t);
//             var o = n.total;
//             var i = n.isDouble;
//             if (1 == o && (a = this.elementAllocator.chazhao_dange(-1))) {
//                 var r = this.chuangjian_yuansu_duixiang(a);
//                 e.charu_yuansu(r, t);
//                 return !0;
//             }
//             if (2 == o) {
//                 var a = void 0;
//                 if (i) {
//                     var s = e.huoqu_yuansiu_b_layer(t);
//                     var c = s[0] ? s[0].idx : s[1] ? s[1].idx : s[2].idx;
//                     a = this.elementAllocator.chazhao_dange(c);
//                 } else {
//                     a = this.elementAllocator.chazhao_dange(-1);
//                 }
//                 if (a) {
//                     r = this.chuangjian_yuansu_duixiang(a);
//                     e.charu_yuansu(r, t);
//                     return !0;
//                 }
//             }
//             return !1;
//         };
//         t.prototype.tianchong_dange_ceng = function (e, t) {
//             var n = this.elementAllocator;
//             var o = n.icons;
//             if (3 * t > o.length) {
//                 t = Math.floor(o.length / 3);
//             }
//             var i = [];
//             for (var r = 0; r < 3; r++) {
//                 i[r] = [];
//                 for (var a = r * t; a < (r + 1) * t && a < o.length; a++) {
//                     i[r].push(a);
//                 }
//             }
//             for (r = 2; r >= 0; r--) {
//                 var s = i[r].upset();
//                 var c = e.upset();
//                 for (a = 0; a < c.length; a++) {
//                     var l = c[a];
//                     if (a >= s.length) {
//                         break;
//                     }
//                     var u = n.tanchu_tubiao(n.iconsMap[s[a]]);
//                     if (u) {
//                         var p = this.chuangjian_yuansu_duixiang(u);
//                         l.charu_yuansu_to_single(p);
//                     }
//                 }
//             }
//             e.forEach(function (e) {
//                 e.shuaxin_single_zuobiao();
//                 e.shezhi_single_jindu();
//                 e.singlePos.forEach(function (t, n) {
//                     t.shezhi_zhanshi_leixing(e.singlePos.length - n - 1);
//                     t.shizhi_weizhi(1);
//                 });
//             });
//         };
//         t.prototype.huoqu_jisuan_gailv_genju_liebiao = function (e) {
//             var t = e.reduce(function (e, t) {
//                 return e + t;
//             });
//             var n = Math.random() * t;
//             var o = 0;
//             for (var i = 0; i < e.length; i++) {
//                 if (n <= (o += e[i])) {
//                     return i;
//                 }
//             }
//             return 0;
//         };
//         t.prototype.huoqu_youxiao_de_wangge = function () {
//             var e = [];
//             var t = [];
//             for (var n = 0; n < this.array_lattice_list.length; n++) {
//                 var o = this.array_lattice_list[n];
//                 o.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE
//                     ? t.push(o)
//                     : o.type != AL_GAME_HUA_Define.Define.LatticeType.NORMAL || o.isVideoLock || e.push(o);
//             }
//             return {
//                 normals: e,
//                 singles: t
//             };
//         };
//         t.prototype.weizhi_zhuanhuan_dao_wangge = function (e) {
//             var t = e;
//             var n = cc.v2(-this.mapSize.width / 2, this.mapSize.height / 2);
//             var o = Math.floor((t.x - n.x) / AL_GAME_HUA_Define.Define.LATTICE_WIDTH);
//             var i = Math.floor((n.y - t.y) / AL_GAME_HUA_Define.Define.LATTICE_HEIGHT);
//             if (o < 0 || o >= this.map_lattice_list.length || i < 0 || i >= this.map_lattice_list[0].length) {
//                 return null;
//             }
//             var r = this.map_lattice_list[o][i];
//             var a = this.node.convertToWorldSpaceAR(e);
//             return r.jiancha_hit(a) ? r : null;
//         };
//         t.prototype.chuangjian_wangge_duixiang = function () {
//             var e = AL_GAME_HUA_GamePool.GamePool.Instance.get("lattice").getComponent(AL_GAME_HUA_Lattice.default);
//             this.node_layer_lattice.addChild(e.node);
//             return e;
//         };
//         t.prototype.chuangjian_yuansu_duixiang = function (e) {
//             var t = AL_GAME_HUA_GamePool.GamePool.Instance.get("element").getComponent(AL_GAME_HUA_Element.default);
//             this.node_layer_element.addChild(t.node);
//             t.idx = e;
//             this.elements.push(t);
//             if (e in this.map_element_list == 0) {
//                 this.map_element_list[e] = [];
//             }
//             this.map_element_list[e].push(t);
//             return t;
//         };
//         t.prototype.onDestroy = function () {
//             AL_APP_SDK_MANAGER.nodePoolManager.shanchu_pool("element");
//         };
//         __decorate([Y(cc.Node)], t.prototype, "node_layer_back", void 0);
//         __decorate([Y(cc.Node)], t.prototype, "node_layer_lattice", void 0);
//         __decorate([Y(cc.Node)], t.prototype, "node_layer_element", void 0);
//         __decorate([Y(cc.Node)], t.prototype, "node_layer_1_finger", void 0);
//         __decorate([Y(AL_GAME_HUA_PropTips.default)], t.prototype, "button_prop_tips", void 0);
//         return __decorate([w], t);
//     })(AL_GAME_HUA_GameBase.default));
// exports.default = E;


const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_ElementConfig = require("./AL_GAME_HUA_ElementConfig");
const AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
const AL_GAME_HUA_LatticeConfig = require("./AL_GAME_HUA_LatticeConfig");
const AL_GAME_HUA_LevelConfig = require("./AL_GAME_HUA_LevelConfig");
const AL_GAME_HUA_PropConfig = require("./AL_GAME_HUA_PropConfig");
const AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
const AL_GAME_HUA_GameBase = require("./AL_GAME_HUA_GameBase");
const AL_GAME_HUA_GamePool = require("./AL_GAME_HUA_GamePool");
const AL_GAME_HUA_PropTips = require("./AL_GAME_HUA_PropTips");
const AL_GAME_HUA_Element = require("./AL_GAME_HUA_Element");
const AL_GAME_HUA_ElementAllocator = require("./AL_GAME_HUA_ElementAllocator");
const AL_GAME_HUA_Lattice = require("./AL_GAME_HUA_Lattice");
const AL_GAME_HUA_CrashEffect = require("./AL_GAME_HUA_CrashEffect");

const { ccclass, property } = cc._decorator;

@ccclass
class Game extends AL_GAME_HUA_GameBase.default {
    /** 层级管理 */
    @property(cc.Node) node_layer_back = null;
    @property(cc.Node) node_layer_lattice = null;
    @property(cc.Node) node_layer_element = null;
    @property(cc.Node) node_layer_1_finger = null;
    @property(AL_GAME_HUA_PropTips.default) button_prop_tips = null;

    array_lattice_list = [];
    map_lattice_list = [];
    elements = [];
    map_element_list = {};
    is_touch_move_state = false;
    lock_lattice = [];
    mapSize = null;
    levelData = null;
    latticeConfig = null;
    totalLayer = 0;
    elementAllocator = null;
    chooseElement = null;
    gameStep = 0;
    handleStep = 0;
    levelGuide = -1;
    videoLatticeGuide = -1;
    isGameStuck = false;
    recordConf = {};
    isTipping = false;
    tipsDuration = 0;
    timeTipsDuration = 10;
    latticeTipsDuration = 0;
    tipsCD = 0;
    enabledGuide = false;
    isGuiding = false;
    guideDuration = 0;
    guideGroup = [];
    curTipButton = null;
    touchIds = [];
    lastIdx = -1;
    displaceProducts = [];

    /**
     * 预加载操作
     * 初始化地图并加载元素
     */
    async onPreload() {
        console.log("******chushihua_ditu_peizhi");
        this.chushihua_ditu_peizhi();
        console.log("******yibu_jiazai_yuansu");
        await this.yibu_jiazai_yuansu();
    }

    /**
     * 准备操作
     * 显示元素
     */
    async onPrepare() {
        await this.xianshi_yuansu_list();
    }

    /**
     * 游戏开始操作
     * 检查引导并初始化触摸事件
     */
    async chuli_youxi_kaishi() {
        this.jiancha_yindao();
        this.chushihua_chumo_shijian();
    }

    chuli_youxi_shengli() {
        this.node.off(cc.Node.EventType.TOUCH_START, this.handle_event_touch_start, this);
        this.node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_event_touch_move, this);
        this.node.off(cc.Node.EventType.TOUCH_END, this.handle_event_touch_end, this);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_event_touch_end, this);
    }

    chuli_youxi_shibai() {
        this.node.off(cc.Node.EventType.TOUCH_START, this.handle_event_touch_start, this);
        this.node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_event_touch_move, this);
        this.node.off(cc.Node.EventType.TOUCH_END, this.handle_event_touch_end, this);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_event_touch_end, this);
    }

    chuli_youxi_zhanting() {
        cc.director.getScheduler().pauseTarget(this);
    }

    chuli_youxi_jixu() {
        cc.director.getScheduler().resumeTarget(this);
    }

    chuli_youxi_tuichu() { }

    chuli_zhen_gengxin(deltaTime) {
        this.gengxin_daoju_tishi(deltaTime);
        this.gengxin_yindao(deltaTime);
    }

    /**
     * 更新道具提示
     * @param {number} deltaTime - 每帧传入的时间增量
     */
    gengxin_daoju_tishi(deltaTime) {
        const self = this;

        // 检查是否正在显示提示
        if (!this.isTipping) {
            const gameConstInstance = AL_GAME_HUA_GameConst.GameConst.getInstance();
            const gameUI = AL_GAME_HUA_Instance.Instance.Game.gameUI;
            const tipsDurationLimit = gameConstInstance.tips_duration;

            // 检查道具提示是否需要更新
            if (this.tipsDuration >= gameConstInstance.tips_prop_time && this.tipsCD > tipsDurationLimit) {
                const propTips = [
                    {
                        button: gameUI.propButtons[0],
                        tipIdx: 0,
                        weight: 90
                    }
                ];
                this.xianshi_daoju_tishi_suiji(propTips, () => {
                    self.tipsDuration = 0;
                });
            } else {
                this.tipsDuration += deltaTime;
            }

            // 检查时间提示是否需要更新
            if (AL_GAME_HUA_Instance.Instance.Game.huoqu_shengyu_shijian() < 60 && !AL_GAME_HUA_Instance.Instance.Game.isTimePause) {
                if (this.timeTipsDuration >= gameConstInstance.time_prop_time && this.tipsCD > tipsDurationLimit) {
                    const timeButton = gameUI.propButtons[3];
                    this.xianshi_daoju_tishi_suiji(
                        [
                            {
                                button: timeButton,
                                tipIdx: 3,
                                weight: 100
                            }
                        ],
                        () => {
                            self.timeTipsDuration = 0;
                        }
                    );
                } else {
                    this.timeTipsDuration += deltaTime;
                }
            }

            // 检查网格提示是否需要更新
            if (this.latticeTipsDuration >= gameConstInstance.video_lattice_duration && this.tipsCD > tipsDurationLimit) {
                this.xianshi_wangge_tishi(() => {
                    self.latticeTipsDuration = 0;
                });
            } else {
                this.latticeTipsDuration += deltaTime;
            }

            // 检查游戏是否卡住并显示提示
            if (this.isGameStuck && this.tipsCD > 2) {
                const stuckTips = [
                    {
                        button: gameUI.propButtons[1],
                        tipIdx: 5,
                        weight: 60
                    },
                    {
                        button: gameUI.propButtons[2],
                        tipIdx: 4,
                        weight: 30
                    }
                ];
                this.xianshi_daoju_tishi_suiji(stuckTips, () => { });
            }

            // 更新提示冷却时间
            this.tipsCD += deltaTime;
        }
    }


    gengxin_yindao(deltaTime) {
        if (this.enabledGuide && !this.isGuiding) {
            if (this.guideDuration >= AL_GAME_HUA_GameConst.GameConst.getInstance().guide_duration) {
                const map_lattice_list = {};
                const processLattice = (index) => {
                    const currLattice = this.array_lattice_list[index];
                    if (currLattice.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                        currLattice.bianli_layer_list((element) => {
                            if (!currLattice.shifou_suoding) {
                                if (!(element.idx in map_lattice_list)) {
                                    map_lattice_list[element.idx] = [];
                                }
                                map_lattice_list[element.idx].push(element);
                            }
                        });
                    } else if (currLattice.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                        const element = currLattice.huoqu_single_yuansu();
                        if (element) {
                            if (!(element.idx in map_lattice_list)) {
                                map_lattice_list[element.idx] = [];
                            }
                            map_lattice_list[element.idx].push(element);
                        }
                    }
                };

                for (let r = 0; r < this.array_lattice_list.length; r++) {
                    processLattice(r);
                }

                const validIdx = [];
                for (const s in map_lattice_list)
                    if (map_lattice_list[s].length >= 3) {
                        validIdx.push(s);
                    }

                if (validIdx.length > 0) {
                    const randomIdx = validIdx.huoqu_shuzu_zhong_suiji_yige_yuansu();
                    map_lattice_list[randomIdx].forEach((element) => {
                        if (this.guideGroup.length < 3) {
                            element.chuli_yindao();
                            this.guideGroup.push(element);
                        }
                    });
                    this.isGuiding = true;
                }
                this.guideDuration = 0;
            } else {
                this.guideDuration += deltaTime;
            }
        }
    }

    yichu_yindao() {
        this.guideGroup.forEach((element) => {
            element.reset();
        });
        this.guideGroup = [];
        this.isGuiding = false;
    }
    /**
     * 显示网格提示
     * @param {Function} callback - 提示完成后的回调函数
     * @param {Object} targetLattice - 目标网格
     */
    xianshi_wangge_tishi(callback, targetLattice) {
        let self = this;
        // 检查目标网格是否存在
        if (!targetLattice) {
            // 过滤出所有视频锁定的网格
            const videoLockedLattices = this.array_lattice_list.filter(lattice => lattice.isVideoLock);
            // 如果没有视频锁定的网格，将提示持续时间设置为最小安全整数
            if (videoLockedLattices.length === 0) {
                this.latticeTipsDuration = Number.MIN_SAFE_INTEGER;
                return;
            }
            // 随机选取一个网格
            targetLattice = videoLockedLattices.huoqu_shuzu_zhong_suiji_yige_yuansu();
        }

        // 隐藏道具提示
        this.yincang_daoju_tishi();
        this.isTipping = true;

        // 设置提示完成后的回调
        this.button_prop_tips.onHide = function () {
            self.isTipping = false;
            self.tipsCD = 0;
            if (callback) {
                callback();
            }
        };

        // 显示提示
        this.button_prop_tips.show(targetLattice.node, "空货柜引导", cc.v2(50, 10));
    }

    /**
     * 随机显示道具提示
     * @param {Array} tipsArr - 提示数组
     * @param {Function} callback - 提示完成后的回调函数
     */
    xianshi_daoju_tishi_suiji(tipsArr, callback) {
        this.yincang_daoju_tishi();
        let totalWeight = 0;

        // 计算总权重
        tipsArr.forEach(tip => {
            const button = tip.button;
            if (!button.huoqu_shifou_jiesuo()) {
                tip.weight = 0;
            }
            if (button.huoqu_shuliang() === 0) {
                tip.weight /= 1e6;
            }
            totalWeight += tip.weight;
        });

        // 随机选择一个道具提示
        const randomValue = Math.get_random(0, totalWeight);
        let accumulatedWeight = 0;

        for (const tip of tipsArr) {
            accumulatedWeight += tip.weight;
            if (accumulatedWeight > randomValue) {
                this.xianshi_daoju_tishi(tip.button, tip.tipIdx, callback);
                return;
            }
        }

        if (callback) {
            callback();
        }
    }

    /**
     * 显示道具提示
     * @param {Object} button - 按钮对象
     * @param {number} tipIdx - 提示索引
     * @param {Function} callback - 提示完成后的回调函数
     */
    xianshi_daoju_tishi(button, tipIdx, callback) {
        let self = this;
        this.isTipping = true;
        button.breath_donghua();
        this.curTipButton = button;

        // 设置提示完成后的回调
        this.button_prop_tips.onHide = function () {
            self.isTipping = false;
            self.tipsCD = 0;
            button.tingzhi_donghua();
            self.curTipButton = null;
            if (callback) {
                callback();
            }
        };

        // 显示提示
        const tipMessages = ["消除3个物品", "刷新所有物品", "变换9个物品", "冻结15秒", "变换9个物品2", "刷新所有物品2"];
        this.button_prop_tips.show(button.node, tipMessages[tipIdx]);
    }

    /**
     * 隐藏道具提示
     */
    yincang_daoju_tishi() {
        if (this.button_prop_tips) {
            this.button_prop_tips.hide();
        }
        if (this.curTipButton) {
            this.curTipButton.tingzhi_donghua();
            this.curTipButton = null;
        }
        this.isTipping = false;
    }

    /**
     * 初始化地图配置，根据当前关卡类型获取相应的关卡配置。
     * 根据配置创建地图和生成元素。
     */
    chushihua_ditu_peizhi() {
        // 获取游戏数据实例
        const gameDataInstance = AL_GAME_HUA_GameData.GameData.getInstance();
        let config;

        // 根据不同的关卡类型获取对应的配置
        if (AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.NORMAL) {
            // 普通关卡配置
            config = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_peizhi_by_level(
                gameDataInstance.huoqu_yijiesuo_guanqia()
            );
        } else if (AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.CHALLENGE) {
            // 挑战关卡配置
            config = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_peizhi_by_date(
                AL_GAME_HUA_Instance.Instance.ChallengeLevel
            );
        } else if (AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.SPECIAL) {
            // 特殊关卡配置
            const minLevel = Math.min(
                gameDataInstance.huoqu_yijiesuo_teshu_guanqia(),
                AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_zong_shuliang()
            );
            config = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_peizhi_by_level(minLevel);
        }

        // 将配置保存为类的属性
        this.levelData = config;

        // 从配置中获取地图相关数据
        const shelfType = config.shelf_type;
        const lattice = config.Lattce;
        const specialGrid = config.Specialgrid2;

        // 根据类型创建地图并生成元素
        this.chuangjian_ditu_by_leixing(shelfType, lattice, specialGrid);
        this.shengcheng_yuansu();
    }

    chushihua_chumo_shijian() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.handle_event_touch_start, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.handle_event_touch_move, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.handle_event_touch_end, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.handle_event_touch_end, this);
    }

    handle_event_touch_start(event) {
        if (this.touchIds.length < 1) {
            this.touchIds.push(event.getID());
            const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
            if (gameData.handleMode === 0) {
                this.handle_touch_start_0(event);
            } else if (gameData.handleMode === 1) {
                this.handle_touch_start_1(event);
            }
        }
    }

    handle_event_touch_move(event) {
        if (this.touchIds.length <= 1) {
            if (this.chooseElement) {
                const gameInstance = AL_GAME_HUA_Instance.Instance.Game;
                if (!gameInstance.isStartTime) {
                    gameInstance.isStartTime = true;
                }
                const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
                if (gameData.handleMode === 0) {
                    this.handle_touch_move_0(event);
                } else if (gameData.handleMode === 1) {
                    this.handle_touch_move_1(event);
                }
            }
        }
    }

    handle_event_touch_end(event) {
        if (this.touchIds.length <= 1) {
            this.touchIds = [];
            if (this.chooseElement) {
                const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
                if (gameData.handleMode === 0) {
                    this.handle_touch_end_0(event);
                } else if (gameData.handleMode === 1) {
                    if (this.is_touch_move_state || this.chooseElement.isMove) {
                        this.handle_touch_end_0(event);
                    } else {
                        this.handle_touch_end_1(event);
                    }
                }
                this.is_touch_move_state = false;
            }
        }
    }

    huoqu_zuobiao_suoyin(lattice, position) {
        const offset = -lattice.node_area_space.width / 2;
        return Math.clamp(Math.floor((position.x - offset) / (lattice.node_area_space.width / 3)), 0, 2);
    }
    /**
     * 根据世界坐标寻找节点中的一个元素。
     * @param {cc.Vec2} worldPosition - 世界坐标。
     * @returns {?Element} 返回找到的元素或 null。
     */
    chazhao_yuansu(worldPosition) {
        const nodePosition = this.node.convertToNodeSpaceAR(worldPosition);
        const latticeInfo = this.weizhi_zhuanhuan_dao_wangge(nodePosition);

        if (!latticeInfo) {
            return null;
        }

        const { type, shifou_suoding, node_area_space, singlePos } = latticeInfo;
        const latticeType = AL_GAME_HUA_Define.Define.LatticeType;

        if (type === latticeType.NULL) {
            return null;
        }

        if (type === latticeType.NORMAL && shifou_suoding) {
            this.touchIds = [];
            return null;
        }

        const localPosition = node_area_space.convertToNodeSpaceAR(worldPosition);
        const index = this.huoqu_zuobiao_suoyin(latticeInfo, localPosition);
        let element = null;

        if (type === latticeType.SINGLE) {
            if (index === 1 && singlePos.length > 0) {
                element = latticeInfo.huoqu_single_yuansu();
            }
        } else if (type === latticeType.NORMAL) {
            const elements = latticeInfo.huoqu_yuansiu_b_layer();
            const emptyCount = latticeInfo.huoqu_wangge_kong_shuliang();

            if (emptyCount < 3) {
                element = elements[index] ||
                    (index === 1 ? (localPosition.x > 0 ? elements[2] || elements[0] : elements[0] || elements[2]) :
                        index === 2 ? elements[1] || elements[0] :
                            index === 0 ? elements[1] || elements[2] : null);
            }
        }

        return element;
    }

    fanhui_dao_origin() {
        this.handleStep++;
        AL_GAME_HUA_Common.Common.vibrate(false);
        this.chooseElement.yidong_dao_weizhi();
        this.jiancha_gezi_shifou_wancheng(this.chooseElement.belone);
    }

    /**
     * 将元素放入网格中
     * @param {Object} e - 当前网格
     * @param {Object} t - 元素位置
     * @param {Object} n - 检查状态对象
     */
    fangru_wangge_zhong = function (currentGrid, elementPosition, checkStatus) {
        this.gameStep++;
        this.handleStep++;
        const originalGrid = this.chooseElement.belone;

        if (originalGrid !== currentGrid) {
            if (originalGrid.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                originalGrid.yichu_yuansu_from_single();
                this.jiancha_dange_gezi_zhuangtai(originalGrid);
            } else if (originalGrid.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                originalGrid.yichu_yuansu(this.chooseElement);
                if (this.jiancha_wangge_kong_zhuangtai(originalGrid)) {
                    checkStatus.check = true;
                }
            }

            if (currentGrid.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                currentGrid.tianjia_yuansu_to_single(this.chooseElement);
                this.jiancha_dange_gezi_zhuangtai(currentGrid);
            } else if (currentGrid.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                const positionIndex = this.huoqu_zuobiao_suoyin(currentGrid, elementPosition);
                currentGrid.tianjia_yuansu(this.chooseElement, positionIndex);

                if (this.jiancha_gezi_shifou_wancheng(currentGrid)) {
                    checkStatus.check = true;
                    checkStatus.complete = true;
                }
            }
        } else {
            if (currentGrid.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                if (this.is_touch_move_state || this.chooseElement.isMove) {
                    this.chooseElement.yidong_dao_weizhi();
                }
                checkStatus.same = true;
            } else if (currentGrid.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                const positionIndex = this.huoqu_zuobiao_suoyin(currentGrid, elementPosition);
                if (positionIndex !== this.chooseElement.posIdx || this.is_touch_move_state || this.chooseElement.isMove) {
                    currentGrid.yichu_yuansu(this.chooseElement);
                    currentGrid.tianjia_yuansu(this.chooseElement, positionIndex);

                    if (this.jiancha_gezi_shifou_wancheng(currentGrid)) {
                        checkStatus.check = true;
                        checkStatus.complete = true;
                    }
                } else {
                    checkStatus.same = true;
                }
            }
        }
    };

    handle_touch_start_0(event) {
        const location = event.getLocation();
        const nodePosition = this.node.convertToNodeSpaceAR(location);
        const element = this.chazhao_yuansu(location);

        if (element) {
            this.chooseElement = element;
            AL_GAME_HUA_Common.Common.bofang_yinxiao("m3d_click", this);
            if (this.guideGroup.includes(this.chooseElement)) {
                this.yichu_yindao();
            }
            element.chuli_xuanze_zhuangtai();
            element.shezhi_miaobian(true);
            element.chuli_tuodong_zhuangtai();
            const offset = cc.v2(0, AL_GAME_HUA_Define.Define.FINGER_OFFSET);
            element.node.setPosition(nodePosition.add(offset));
        }
    }

    handle_touch_move_0(event) {
        const nodePosition = this.node.convertToNodeSpaceAR(event.getLocation());
        this.chooseElement.node.setPosition(nodePosition.add(cc.v2(0, AL_GAME_HUA_Define.Define.FINGER_OFFSET)));
    }

    handle_touch_start_1(event) {
        const location = event.getLocation();
        const nodePosition = this.node.convertToNodeSpaceAR(location);
        const lattice = this.weizhi_zhuanhuan_dao_wangge(nodePosition);

        if (lattice) {
            if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.NULL) {
                return;
            }
            if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL && lattice.shifou_suoding) {
                this.touchIds = [];
                return;
            }

            const spacePosition = lattice.node_area_space.convertToNodeSpaceAR(location);
            const posIdx = this.huoqu_zuobiao_suoyin(lattice, spacePosition);
            let targetElement = null;

            if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                if (posIdx === 1) {
                    if (this.chooseElement && !lattice.shifou_man) {
                        if (lattice.jiancha_hit_rq(location)) {
                            const result = { check: false, complete: false, same: false };
                            this.fangru_wangge_zhong(lattice, spacePosition, result);
                            this.jiancha_chumo_jieguo(result);
                            return;
                        }
                    }
                    targetElement = lattice.huoqu_single_yuansu();
                }
            } else if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                const elementsByLayer = lattice.huoqu_yuansiu_b_layer();
                if (this.chooseElement && !lattice.shifou_man) {
                    if (lattice.jiancha_hit_rq(location)) {
                        const result = { check: false, complete: false, same: false };
                        this.fangru_wangge_zhong(lattice, spacePosition, result);
                        this.jiancha_chumo_jieguo(result);
                        return;
                    }
                    if (!elementsByLayer[posIdx]) {
                        const result = { check: false, complete: false, same: false };
                        this.fangru_wangge_zhong(lattice, spacePosition, result);
                        this.jiancha_chumo_jieguo(result);
                        return;
                    }
                }

                if (lattice.huoqu_wangge_kong_shuliang() < 3) {
                    if (elementsByLayer[posIdx]) {
                        targetElement = elementsByLayer[posIdx];
                    } else if (posIdx === 1) {
                        targetElement = spacePosition.x > 0 ? (elementsByLayer[2] || elementsByLayer[0]) : (elementsByLayer[0] || elementsByLayer[2]);
                    } else if (posIdx === 2) {
                        targetElement = elementsByLayer[1] || elementsByLayer[0];
                    } else if (posIdx === 0) {
                        targetElement = elementsByLayer[1] || elementsByLayer[2];
                    }
                }
            }

            if (targetElement) {
                if (this.chooseElement) {
                    this.chooseElement.reset();
                }
                this.chooseElement = targetElement;
                AL_GAME_HUA_Common.Common.bofang_yinxiao("m3d_click", this);
                if (this.guideGroup.includes(this.chooseElement)) {
                    this.yichu_yindao();
                }
                targetElement.chuli_xuanze_zhuangtai();
                targetElement.shezhi_miaobian(true);
            }
        }
    }

    handle_touch_move_1(event) {
        const chosenElement = this.chooseElement;
        const nodePosition = this.node.convertToNodeSpaceAR(event.getLocation());

        if (this.is_touch_move_state) {
            chosenElement.node.setPosition(nodePosition);
        } else if (event.getLocation().sub(event.getStartLocation()).magSqr() >= Math.pow(AL_GAME_HUA_Define.Define.TOUCH_MOVE_LIMIT, 2)) {
            this.is_touch_move_state = true;
            chosenElement.chuli_tuodong_zhuangtai();
            chosenElement.node.setPosition(nodePosition);
        }
    }

    handle_touch_end_0() {
        const adjust = cc.v2(0, this.chooseElement.node.height / 2).sub(cc.v2(0, AL_GAME_HUA_Define.Define.FINGER_OFFSET));
        const position = this.chooseElement.node.getPosition().add(adjust);
        const worldSpace = this.chooseElement.node.convertToWorldSpaceAR(adjust);

        const lattice = this.weizhi_zhuanhuan_dao_wangge(position);
        const result = { check: false, complete: false, same: false };

        if (lattice) {
            if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                if (!lattice.shifou_suoding && !lattice.shifou_man) {
                    this.fangru_wangge_zhong(lattice, lattice.node_area_space.convertToNodeSpaceAR(worldSpace), result);
                } else {
                    this.fanhui_dao_origin();
                }
            } else if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                if (!lattice.shifou_man) {
                    this.fangru_wangge_zhong(lattice, lattice.node_area_space.convertToNodeSpaceAR(worldSpace), result);
                } else {
                    this.fanhui_dao_origin();
                }
            } else {
                this.fanhui_dao_origin();
            }
        } else {
            this.fanhui_dao_origin();
        }

        this.jiancha_chumo_jieguo(result);
    }

    handle_touch_end_1() { }

    jiancha_chumo_jieguo(result) {
        if (result.check) {
            this.jiancha_youxi_shifou_bei_kazhu();
        }
        if (result.complete) {
            this.yincang_daoju_tishi();
        } else {
            AL_GAME_HUA_Common.Common.bofang_yinxiao("put", this);
            AL_GAME_HUA_Common.Common.vibrate(false);
        }
        if (!result.same) {
            this.chooseElement = null;
        }
    }

    jiancha_yindao() {
        if (AL_GAME_HUA_Instance.Instance.LevelType !== AL_GAME_HUA_Define.Define.LevelType.CHALLENGE) {
            if (AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() === 1) {
                if (this.levelGuide === -1) {
                    this.levelGuide = 0;
                }
                if (this.levelGuide === 0) {
                    this.node_layer_1_finger.active = true;
                    const element = this.elements[4];
                    const worldPos = element.belone.node.convertToWorldSpaceAR(cc.v2(AL_GAME_HUA_Define.Define.LATTICE_POS[element.posIdx]));
                    const localPos = this.node_layer_1_finger.parent.convertToNodeSpaceAR(worldPos);
                    const latticeNode = this.array_lattice_list[1].node;
                    const latticeWorldPos = latticeNode.convertToWorldSpaceAR(AL_GAME_HUA_Define.Define.LATTICE_POS[2]);
                    const latticeLocalPos = this.node_layer_1_finger.parent.convertToNodeSpaceAR(latticeWorldPos);
                    this.shou_yidong_dongzuo(localPos, latticeLocalPos);
                } else if (this.levelGuide === 1) {
                    const element = this.elements[2];
                    const worldPos = element.belone.node.convertToWorldSpaceAR(cc.v2(AL_GAME_HUA_Define.Define.LATTICE_POS[element.posIdx]));
                    const localPos = this.node_layer_1_finger.parent.convertToNodeSpaceAR(worldPos);
                    const latticeNode = this.array_lattice_list[0].node;
                    const latticeWorldPos = latticeNode.convertToWorldSpaceAR(AL_GAME_HUA_Define.Define.LATTICE_POS[0]);
                    const latticeLocalPos = this.node_layer_1_finger.parent.convertToNodeSpaceAR(latticeWorldPos);
                    if (this.array_lattice_list[0].huoqu_wangge_zhuangtai().same === 2) {
                        this.shou_yidong_dongzuo(localPos, latticeLocalPos);
                    }
                } else if (this.levelGuide === 2) {
                    this.node_layer_1_finger.active = false;
                }
            }

            const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
            const unlockLevel = gameData.huoqu_yijiesuo_guanqia();
            const propConfig = AL_GAME_HUA_PropConfig.PropConfig.getInstance();
            const propIds = [
                AL_GAME_HUA_PropConfig.PropId.TIPS_GAME,
                AL_GAME_HUA_PropConfig.PropId.REFRESH_GAME,
                AL_GAME_HUA_PropConfig.PropId.CHANGE_GAME,
                AL_GAME_HUA_PropConfig.PropId.TIME_GAME
            ];
            propIds.forEach((propId, index) => {
                const requiredUnlockLevel = propConfig.huoqu_peizhi_genju_id(propId).unlock;
                if (!gameData.huoqu_prop_jiesuo(propId) && unlockLevel === requiredUnlockLevel) {
                    AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jiesuo_mianban({
                        propButton: AL_GAME_HUA_Instance.Instance.Game.gameUI.propButtons[index]
                    });
                    gameData.shezhi_prop_jiesuo(propId);
                }
            });

            if (
                AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.NORMAL &&
                unlockLevel === AL_GAME_HUA_GameConst.GameConst.getInstance().video_lattice_unlock &&
                this.videoLatticeGuide === -1
            ) {
                this.videoLatticeGuide = 0;
                this.node_layer_1_finger.active = true;
                const lattice = this.map_lattice_list[2][3];
                const worldPos = lattice.node.convertToWorldSpaceAR(cc.v2(0, -20));
                const localPos = this.node_layer_1_finger.parent.convertToNodeSpaceAR(worldPos);
                this.node_layer_1_finger.setPosition(localPos);
                this.node_layer_1_finger.scale = 0.7;
                this.node_layer_1_finger.stopAllActions();
                cc.tween(this.node_layer_1_finger)
                    .to(0.5, { scale: 0.75 })
                    .to(0.5, { scale: 0.7 })
                    .union()
                    .repeatForever()
                    .start();
                this.xianshi_wangge_tishi(() => {
                    this.node_layer_1_finger.active = false;
                }, lattice);
                this.videoLatticeGuide++;
            }
        }
    }

    /** 
    * 检查游戏是否被卡住
    * @returns {boolean} 如果没有卡住返回 true，否则返回 false
    */
    _jiancha_youxi_shifou_bei_kazhu() {
        let emptyCount = 0; // 记录空格子的数量
        let singleCount = 0; // 记录单格子的数量
        const map_lattice_list = {}; // 存储每个层次的格子

        // 遍历所有格子
        for (let index = 0; index < this.array_lattice_list.length; index++) {
            const lattice = this.array_lattice_list[index];

            // 处理正常类型的格子
            if (lattice.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                if (!lattice.shifou_suoding) {
                    emptyCount += lattice.huoqu_wangge_kong_shuliang();

                    lattice.bianli_layer_list(layerElement => {
                        if (!(layerElement.idx in map_lattice_list)) {
                            map_lattice_list[layerElement.idx] = [];
                        }
                        map_lattice_list[layerElement.idx].push(layerElement);
                    });

                    if (emptyCount >= 3) {
                        return false;
                    }
                }
            } else if (lattice.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                // 处理单格子类型
                singleCount += 3 - lattice.singlePos.length;
                lattice.singlePos.forEach(singleElement => {
                    if (!(singleElement.idx in map_lattice_list)) {
                        map_lattice_list[singleElement.idx] = [];
                    }
                    map_lattice_list[singleElement.idx].push(singleElement);
                });

                if (singleCount >= 3) {
                    return false;
                }
            }

            if (emptyCount + singleCount >= 3) {
                return false;
            }
        }

        // 进一步检查是否有拼接出3个以上相同类型的格子
        if (emptyCount + singleCount > 0) {
            const totalCount = emptyCount + singleCount;
            for (const key in map_lattice_list) {
                if (map_lattice_list[key].length >= 3) {
                    let validCount = 0;

                    for (const element of map_lattice_list[key]) {
                        if (element.belone.type != AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                            if (element.belone.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                                const positionIndex = element.belone.singlePos.indexOf(element);
                                if (positionIndex === 3 || (positionIndex === 2 && totalCount > 1)) {
                                    validCount++;
                                    continue;
                                }
                            }
                        } else {
                            validCount++;
                        }

                        if (validCount >= 3) {
                            this.tipsDuration = AL_GAME_HUA_GameConst.GameConst.getInstance().tips_prop_time;
                            return false;
                        }
                    }
                }
            }
        }

        return true;
    }

    jiancha_youxi_shifou_bei_kazhu() {
        this.isGameStuck = this._jiancha_youxi_shifou_bei_kazhu();
        if (this.isGameStuck) {
            this.tipsCD = AL_GAME_HUA_GameConst.GameConst.getInstance().tips_duration;
        }
    }

    shou_yidong_dongzuo(from, to) {
        const finger = this.node_layer_1_finger;
        finger.active = true;
        finger.setPosition(from);
        finger.stopAllActions();
        cc.tween(finger)
            .to(0.1, { scale: 0.8 })
            .to(0.85, { position: cc.v3(to) })
            .to(0.1, { scale: 1 })
            .to(0.85, { position: cc.v3(from) })
            .union()
            .repeatForever()
            .start();
    }
    /**
     * 检查格子的空状态
     * @param {Object} lattice - 格子对象
     * @param {Object} layer - 层对象
     * @returns {boolean} 是否符合条件
     */
    jiancha_wangge_kong_zhuangtai(lattice, layer) {
        if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL &&
            lattice.huoqu_wangge_kong_shuliang(layer) === 3) {
            lattice.qingkong_layer(layer);
            this.tipsDuration = 0;
            this.guideDuration = 0;
            return true;
        }
        return false;
    };

    /**
     * 检查单个格子的状态
     * @param {Object} lattice - 单个格子对象
     */
    jiancha_dange_gezi_zhuangtai(lattice) {
        if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
            let stepCount = 0;
            for (let i = lattice.singlePos.length - 1; i >= 0; i--) {
                const position = lattice.singlePos[i];
                if (stepCount === 0 && position.showType !== AL_GAME_HUA_Define.Define.ElementShowType.ACTIVE) {
                    position.chuli_jianxian_zhanshi();
                } else if (stepCount === 1) {
                    if (position.showType === AL_GAME_HUA_Define.Define.ElementShowType.ACTIVE) {
                        position.chuli_huidu_danru();
                    } else if (position.showType === AL_GAME_HUA_Define.Define.ElementShowType.HIDE) {
                        position.chuli_yincang_zhanshi();
                    }
                } else if (stepCount === 2 && position.showType === AL_GAME_HUA_Define.Define.ElementShowType.GRAY) {
                    position.chuli_yincang_danchu();
                }
                stepCount++;
            }
        }
    };

    /**
     * 检查格子层是否完成
     * @param {Object} lattice - 格子对象
     * @returns {boolean} 是否完成
     */
    jiancha_gezi_shifou_wancheng(lattice) {
        if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
            return false;
        }
        if (lattice.huoqu_wangge_zhuangtai().isComplete) {
            const elements = lattice.huoqu_yuansiu_b_layer();
            lattice.bianli_layer_list(layer => {
                if (this.guideGroup.includes(layer)) {
                    this.yichu_yindao();
                }
                this.yichu_yuansu(layer);
            });
            lattice.isAnimating = true;
            this.chooseElement.yidong_dao_weizhi().then(() => {
                let effectCreated = false;
                elements.forEach(element => {
                    element.chuli_pengzhuang_xiaohuo(() => {
                        if (!effectCreated) {
                            lattice.chuangjian_pengzhuang_xiaoguo(element.idx);
                            effectCreated = true;
                        }
                    });
                });
                lattice.isAnimating = false;
                lattice.qingkong_layer();
                this.chuli_crash(lattice.node);
            });
            AL_GAME_HUA_Instance.Instance.Game.gameUI.popNum++;
            if (this.levelGuide >= 0) {
                this.levelGuide++;
                this.jiancha_yindao();
            }
            return AL_GAME_HUA_Instance.Instance.Game.gameState !== AL_GAME_HUA_Define.Define.GameState.WIN;
        }
        if (this.levelGuide >= 0) {
            this.node_layer_1_finger.active = false;
        }
        return false;
    };

    jiancha_suoyou_gezi_shifou_wancheng() {
        const noElementsLeft = this.elements.length === 0;
        if (noElementsLeft) {
            AL_GAME_HUA_Instance.Instance.Game.chuli_youxi_shengli();
            return true;
        }
        return false;
    }

    chuli_crash(node) {
        if (ailin_sdk_manager.getSysPlatformName() === "tt") {
            AL_GAME_HUA_Common.Common.vibrate(false);
        } else if (ailin_sdk_manager.getSysPlatformName() === "wx") {
            AL_GAME_HUA_Common.Common.vibrate(true);
        } else {
            AL_GAME_HUA_Common.Common.vibrate(false);
        }

        this.enabledGuide = true;
        const starMultiplier = Math.min(5, Math.floor(AL_GAME_HUA_Instance.Instance.Game.gameUI.comboCount / 3) + 1) * (AL_GAME_HUA_GameData.GameData.getInstance().useStarEnter ? 2 : 1);
        AL_GAME_HUA_Instance.Instance.Game.gameUI.chuangjian_xingxing(node, starMultiplier);
        AL_GAME_HUA_Instance.Instance.Game.gameUI.xianshi_combo(node);
        if (!this.jiancha_suoyou_gezi_shifou_wancheng()) {
            this.tipsDuration = 0;
            this.guideDuration = 0;
            this.yincang_daoju_tishi();
            this.jiesuo_wangge();
        }
    }

    jiesuo_wangge() {
        if (this.lock_lattice.length > 0) {
            const lattice = this.lock_lattice[0];
            if (lattice.shifou_suoding) {
                lattice.chuli_jiesuo();
                if (!lattice.shifou_suoding) {
                    this.lock_lattice.shift();
                }
            }
        }
    }

    yichu_yuansu(element) {
        const index = this.elements.indexOf(element);
        if (index > -1) this.elements.splice(index, 1);

        if (element.idx in this.map_element_list) {
            const mapIndex = this.map_element_list[element.idx].indexOf(element);
            if (mapIndex > -1) this.map_element_list[element.idx].splice(mapIndex, 1);
            if (this.map_element_list[element.idx].length === 0) {
                delete this.map_element_list[element.idx];
            }
        }
        this.shuaxin_jindu();
    }
    /**
     * 处理提示逻辑
     * 
     * 该函数异步执行，根据当前棋盘状态，执行一系列操作用于提示玩家可能的操作。
     */
    async chuli_tishi_luoji() {
        return __awaiter(this, void 0, void 0, function () {
            let elementGroups = {}; // 保存元素分组的对象
            let normalTypeGroups = []; // 普通类型的元素组
            let doubleTypeGroups = []; // 双元素组
            let singleTypeGroups = []; // 单元素组
            let firstGroup; // 第一个有效组
            let latticeTypeNormal = AL_GAME_HUA_Define.Define.LatticeType.NORMAL;
            let latticeTypeSingle = AL_GAME_HUA_Define.Define.LatticeType.SINGLE;
            let latticePositions = AL_GAME_HUA_Define.Define.LATTICE_POS;
            let tipsDuration = 0;
            let guideDuration = 0;
            let animationPromises = [];
            let hasCreatedEffect = false;
            let latticeIndex;

            return __generator(this, function (state) {
                switch (state.label) {
                    case 0:
                        // 遍历棋盘上所有的格子
                        for (let index = 0; index < this.array_lattice_list.length; index++) {
                            let lattice = this.array_lattice_list[index];
                            if (lattice.type === latticeTypeNormal) {
                                lattice.bianli_layer_list(element => {
                                    if (!(element.idx in elementGroups)) {
                                        elementGroups[element.idx] = [];
                                    }
                                    elementGroups[element.idx].push(element);
                                });
                            } else if (lattice.type === latticeTypeSingle) {
                                let singleElement = lattice.huoqu_single_yuansu();
                                if (singleElement) {
                                    if (!(singleElement.idx in elementGroups)) {
                                        elementGroups[singleElement.idx] = [];
                                    }
                                    elementGroups[singleElement.idx].push(singleElement);
                                }
                            }
                        }

                        // 对元素进行分类
                        for (let key in elementGroups) {
                            let group = elementGroups[key];
                            if (group.length >= 3) {
                                normalTypeGroups.push(key);
                            } else if (group.length === 2) {
                                doubleTypeGroups.push(key);
                            } else if (group.length === 1) {
                                singleTypeGroups.push(key);
                            }
                        }

                        // 打乱顺序找出第一个有效组
                        if ((firstGroup = __spreadArrays(normalTypeGroups.upset(), doubleTypeGroups.upset(), singleTypeGroups.upset())).length === 0) {
                            console.error("未能找到1组元素");
                            return [2];
                        }

                        let currentGroup = elementGroups[firstGroup[0]];
                        if (currentGroup.length < 3) {
                            latticeIndex = currentGroup[0].idx;
                            let potentialMatches = this.map_element_list[latticeIndex];
                            for (let i = 0; i < potentialMatches.length; i++) {
                                let potentialElement = potentialMatches[i];
                                if (!currentGroup.includes(potentialElement)) {
                                    currentGroup.push(potentialElement);
                                }
                                if (currentGroup.length >= 3) {
                                    break;
                                }
                            }
                        }

                        // 选出前3个元素进行操作
                        let selectedElements = [];
                        for (let i = 0; i < currentGroup.length && selectedElements.length < 3; i++) {
                            selectedElements.push(currentGroup[i]);
                        }

                        // 对选出的元素进行处理
                        selectedElements.sort((a, b) => a.node.x - b.node.x)
                            .forEach((element, index) => {
                                let lattice = element.belone;
                                if (lattice.type === latticeTypeNormal) {
                                    lattice.yichu_yuansu(element, element.layer);
                                    this.jiancha_wangge_kong_zhuangtai(lattice, element.layer);
                                } else if (lattice.type === latticeTypeSingle) {
                                    lattice.yichu_yuansu_from_single();
                                    this.jiancha_dange_gezi_zhuangtai(lattice);
                                }
                                this.yichu_yuansu(element);

                                if (this.guideGroup.includes(element)) {
                                    this.yichu_yindao();
                                }

                                animationPromises.push(element.chuli_yidong_pengzhuang_xiaohuo(
                                    latticePositions[index].mul(1.5),
                                    AL_GAME_HUA_Define.Define.LATTICE_ANGLE[index],
                                    () => {
                                        if (!hasCreatedEffect) {
                                            this.chuangjian_yidong_crash_texiao(latticePositions[1].mul(1.5).add(cc.v2(0, 180)), element.idx, 1.6);
                                            hasCreatedEffect = true;
                                        }
                                    }
                                ));
                            });

                        return [4, Promise.all(animationPromises)];
                    case 1:
                        state.sent();
                        this.chuli_crash(this.node);
                        this.jiancha_youxi_shifou_bei_kazhu();
                        return [2];
                }
            });
        });
    }


    chuangjian_yidong_crash_texiao(position, elementIndex, scale) {
        const effectIndex = Math.get_random_int(0, 3);
        const crashEffect = AL_GAME_HUA_GamePool.GamePool.Instance.get(`crashEffect${effectIndex}`);
        crashEffect.zIndex = 1020;
        crashEffect.scale = scale || 1;
        crashEffect.getComponent(AL_GAME_HUA_CrashEffect.default).refresh(elementIndex);
        this.node.addChild(crashEffect);
        crashEffect.setPosition(position);
        this.scheduleOnce(() => {
            AL_GAME_HUA_GamePool.GamePool.Instance.put(crashEffect);
        }, 2);
    }
    /**
     * shuaxin_daoju_he_yuansu_zhuangtai - 刷新游戏道具和元素状态
     * 根据游戏的不同等级类型，重置游戏元素并分配到合适的格子中。
     */
    shuaxin_daoju_he_yuansu_zhuangtai() {
        this.yichu_yindao(); // 移除引导

        // 获取元素ID的数组
        const elementIds = Object.keys(this.map_element_list).map(id => Number(id));
        const elementTypeCount = elementIds.length; // 元素类型数量
        const totalElementCount = this.elements.length; // 总元素数量

        // 重置所有格子
        this.array_lattice_list.forEach(lattice => {
            lattice.reset();
        });

        // 回收所有元素节点
        this.elements.forEach(element => {
            AL_GAME_HUA_GamePool.GamePool.Instance.put(element.node);
        });

        // 清空元素及映射
        this.elements = [];
        this.map_element_list = [];

        // 判断当前关卡类型
        if (
            AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.CHALLENGE ||
            AL_GAME_HUA_Common.Common.shifou_keyi_kaiqi_tiaozhan_guanqia()
        ) {
            // 初始化记录配置
            this.recordConf = {
                displaceCount: 0,
                displaceElement: 0,
                layerDisRate: {},
                layerDisCount: {},
                displaceLayers: 0,
                displaceLayerFb: {},
                layerInfos: []
            };

            // 初始化元素分配器
            this.elementAllocator = new AL_GAME_HUA_ElementAllocator.ElementAllocator({
                icons: elementIds,
                type: elementTypeCount,
                count: totalElementCount
            });

            const validLattices = this.huoqu_youxiao_de_wangge();
            const normalLattices = validLattices.normals;
            const singleLattices = validLattices.singles;

            const totalSlots = Math.ceil(totalElementCount / (3 * 0.7 * normalLattices.length));
            const complexLayerCount = Math.floor((totalSlots / 3) * 2);
            const simpleLayerCount = Math.floor(totalSlots / 3);

            if (singleLattices.length > 0) {
                this.tianchong_dange_ceng(singleLattices, normalLattices.length + singleLattices.length);
            }

            for (let layerIndex = 0; this.elementAllocator.iconsLenght > 0; layerIndex++) {
                this.tianchong_wangge_ceng({
                    layer: layerIndex,
                    normals: normalLattices.slice().upset(),
                    empty: this.levelData.Empty,
                    space: layerIndex <= simpleLayerCount ? 0 : layerIndex <= complexLayerCount ? 1 : 2
                });
            }

            this.displaceProducts = [];

            for (let layerIndex = 0; layerIndex < totalSlots; layerIndex++) {
                this.zhixing_cengji_weiyi_caozuo({
                    layer: layerIndex,
                    normals: normalLattices,
                    space: layerIndex <= simpleLayerCount ? 0 : layerIndex <= complexLayerCount ? 1 : 2
                });
            }

            const layerInfos = [];
            for (let layerIndex = 0; layerIndex < totalSlots; layerIndex++) {
                const layerInfo = this.jisuan_cengji_xinxi(layerIndex, normalLattices, singleLattices);
                layerInfos.push(layerInfo);
            }
            this.recordConf.layerInfos = layerInfos;
        } else if (
            AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.NORMAL ||
            AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.SPECIAL
        ) {
            this.elementAllocator = new AL_GAME_HUA_ElementAllocator.ElementAllocator({
                icons: elementIds,
                type: elementTypeCount,
                count: totalElementCount
            });

            const validLattices = this.huoqu_youxiao_de_wangge();
            const normalLattices = validLattices.normals;
            const singleLattices = validLattices.singles;

            const totalSlots = Math.ceil(totalElementCount / (3 * 0.7 * normalLattices.length));
            const complexLayerCount = Math.floor((totalSlots / 3) * 2);
            const simpleLayerCount = Math.floor(totalSlots / 3);

            if (singleLattices.length > 0) {
                this.tianchong_dange_ceng(singleLattices, normalLattices.length + singleLattices.length);
            }

            for (let layerIndex = 0; this.elementAllocator.iconsLenght > 0; layerIndex++) {
                this.tianchong_wangge_ceng({
                    layer: layerIndex,
                    normals: normalLattices.slice().upset(),
                    empty: this.levelData.Empty,
                    space: layerIndex <= simpleLayerCount ? 0 : layerIndex <= complexLayerCount ? 1 : 2
                });
            }
        }

        // 设置图标和展示创建效果
        this.elements.forEach(element => {
            element.shezhi_tubiao();
            element.chuli_chuangjian_zhanshi();
        });

        this.yincang_daoju_tishi(); // 隐藏道具提示
        this.jiancha_youxi_shifou_bei_kazhu(); // 检查游戏是否卡住

        AL_GAME_HUA_Common.Common.bofang_yinxiao("stick", this); // 播放音效
    }
    daoju_qihuan() {
        this.yichu_yindao();
        AL_GAME_HUA_Common.Common.bofang_yinxiao("refresh", this);
        var e = [];
        var t = new Set();
        for (var n = 0; n < this.array_lattice_list.length; n++) {
            if ((y = this.array_lattice_list[n]).type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                if (y.isVideoLock) {
                    continue;
                }
                y.bianli_layer_list(function (n) {
                    e.push(n);
                    t.add(n.idx);
                });
            } else {
                if (y.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                    var o = y.huoqu_single_yuansu();
                    if (o) {
                        e.push(o);
                        t.add(o.idx);
                    }
                }
            }
        }
        var i = Array.from(t);
        if (this.lastIdx > 0 && i.length > 1) {
            i.remove(this.lastIdx);
        }
        var r = i.huoqu_shuzu_zhong_suiji_yige_yuansu();
        this.lastIdx = r;
        var a = [];
        var s = 0;
        var c = function (e) {
            var t = u.array_lattice_list[e];
            if (t.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                if (t.isVideoLock) {
                    return "continue";
                }
                var n = 0;
                var o = t.huoqu_layer_shuliang();
                for (var i = t.curLayer; i < o; i++) {
                    a[n] || (a[n] = []);
                    t.bianli_layer_list(function (e) {
                        if (e.idx != n) {
                            a[n].push(e);
                            s++;
                        }
                    }, i);
                    n++;
                }
            } else {
                if (t.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                    var r = 0;
                    for (var c = t.singlePos.length - 1; c >= 0; c--) {
                        if (!a[r]) {
                            a[r] = [];
                        }
                        var l = t.singlePos[c];
                        if (l.idx != r) {
                            a[r].push(l);
                            s++;
                        }
                        r++;
                    }
                }
            }
        };
        var u = this;
        for (n = 0; n < this.array_lattice_list.length; n++) {
            c(n);
        }
        var p = Math.min(9, s);
        var h = [];
        a.forEach(function (e) {
            h = __spreadArrays(h, e.upset());
        });
        for (var _ = []; _.length < p;) {
            var P = h[0].idx;
            var g = this.map_element_list[P].slice();
            for (n = 0; n < 3; n++) {
                var y;
                var m = g[n];
                h.remove(m);
                _.push(m);
                if ((y = m.belone).type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                    if (m.layer != y.curLayer) {
                        for (var v = 0; v < h.length; v++) {
                            if (h[v].idx != P) {
                                var D = h[v];
                                var L = {
                                    belone: m.belone,
                                    posIdx: m.posIdx,
                                    layer: m.layer
                                };
                                m.belone.yichu_yuansu(m, m.layer);
                                D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
                                    ? (D.belone.yichu_yuansu(D, D.layer),
                                        D.belone.tianjia_yuansu_dao(m, D.posIdx, D.layer, !0))
                                    : D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
                                    (D.belone.yichu_yuansu_from_single(D), D.belone.tianjia_single_dao(m, D.layer, !0));
                                L.belone.tianjia_yuansu_dao(D, L.posIdx, L.layer, !0);
                                h.remove(D);
                                break;
                            }
                        }
                    }
                } else {
                    if (y.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE && 0 != m.layer) {
                        for (var b = 0; b < h.length; b++) {
                            if (h[b].idx != P) {
                                D = h[b];
                                L = {
                                    belone: m.belone,
                                    posIdx: m.posIdx,
                                    layer: m.layer
                                };
                                m.belone.yichu_yuansu_from_single(m);
                                D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.NORMAL
                                    ? (D.belone.yichu_yuansu(D, D.layer),
                                        D.belone.tianjia_yuansu_dao(m, D.posIdx, D.layer, !0))
                                    : D.belone.type == AL_GAME_HUA_Define.Define.LatticeType.SINGLE &&
                                    (D.belone.yichu_yuansu_from_single(D), D.belone.tianjia_single_dao(m, D.layer, !0));
                                L.belone.tianjia_single_dao(D, L.layer, !0);
                                h.remove(D);
                                break;
                            }
                        }
                    }
                }
                m.chuli_zhuangtai_gaibian(r);
                this.map_element_list[P].remove(m);
                this.map_element_list[r].unshift(m);
            }
        }
        this.yincang_daoju_tishi();
        this.jiancha_youxi_shifou_bei_kazhu();
    };
    /**
     * 时间道具效果逻辑，包括暂停时间、显示冰冻效果和恢复时间
     */
    shijian_daoju_xiaoguo_luoji() {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function () {
                // 设置游戏时间暂停为true
                AL_GAME_HUA_Instance.Instance.Game.isTimePause = true;

                // 激活并初始化冰冻效果节点
                const iceNode = AL_GAME_HUA_Instance.Instance.Game.gameUI.iceNode;
                iceNode.active = true;
                iceNode.opacity = 0;
                iceNode.stopAllActions();

                // 逐步显示冰冻效果
                cc.tween(iceNode)
                    .to(0.5, { opacity: 255 })
                    .start();

                // 播放冰冻音效
                AL_GAME_HUA_Common.Common.bofang_yinxiao("freeze", this);

                // 暂停连击计数
                AL_GAME_HUA_Instance.Instance.Game.gameUI.zhanting_combo();

                // 在预定时间后，恢复游戏状态和连击计数
                this.scheduleOnce(function () {
                    // 取消时间暂停
                    AL_GAME_HUA_Instance.Instance.Game.isTimePause = false;

                    // 恢复连击计数
                    AL_GAME_HUA_Instance.Instance.Game.gameUI.jixu_combo();

                    // 逐步隐藏冰冻效果并在结束时禁用节点
                    cc.tween(iceNode)
                        .to(0.5, { opacity: 0 })
                        .call(function () {
                            iceNode.active = false;
                        })
                        .start();
                }, AL_GAME_HUA_GameConst.GameConst.getInstance().time_prop_duration);

                // 返回无意义值以符合TypeScript生成器要求
                return [2];
            });
        });
    }


    /**
     * 设置地图尺寸
     * @param {number} e - 地图的行数
     * @param {number} t - 地图的列数
     */
    shezhi_ditu_chicun(e, t) {
        // 获取当前窗口的宽高
        const windowWidth = cc.winSize.width;
        const windowHeight = cc.winSize.height;

        // 根据游戏等级类型设置上下边距
        AL_GAME_HUA_Define.Define.Margin.bottom = 180;
        AL_GAME_HUA_Define.Define.Margin.top = AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.CHALLENGE ? 160 : 120;

        // 计算每个格子的宽高
        const latticeWidth = AL_GAME_HUA_Define.Define.getWidth() / t;
        const latticeHeight = AL_GAME_HUA_Define.Define.getHeight() / e;

        // 设置格子的宽度和高度，宽度取最大值，高度取在最小和最大值之间
        AL_GAME_HUA_Define.Define.LATTICE_WIDTH = Math.max(latticeWidth, AL_GAME_HUA_Define.Define.MIN_LATTICE_WIDTH);
        AL_GAME_HUA_Define.Define.LATTICE_HEIGHT = Math.clamp(
            latticeHeight,
            AL_GAME_HUA_Define.Define.MIN_lATTICE_HEIGHT,
            AL_GAME_HUA_Define.Define.MAX_LATTICE_HEIGHT
        );

        // 计算节点缩放比例
        const scaleX = AL_GAME_HUA_Define.Define.getWidth() / (t * AL_GAME_HUA_Define.Define.LATTICE_WIDTH);
        const scaleY = AL_GAME_HUA_Define.Define.getHeight() / (e * AL_GAME_HUA_Define.Define.LATTICE_HEIGHT);

        // 设置地图尺寸和节点的缩放
        this.mapSize = cc.size(
            t * AL_GAME_HUA_Define.Define.LATTICE_WIDTH,
            e * AL_GAME_HUA_Define.Define.LATTICE_HEIGHT
        );
        this.node.scale = Math.min(scaleX, scaleY);

        // 设置节点的位置
        this.node.x = 0;
        this.node.y = AL_GAME_HUA_Define.Define.getCenter();

        // 输出日志信息
        console.log(
            "LATTICE_WIDTH:",
            AL_GAME_HUA_Define.Define.LATTICE_WIDTH,
            "LATTICE_HEIGHT:",
            AL_GAME_HUA_Define.Define.LATTICE_HEIGHT,
            "SCALE:",
            this.node.scale
        );
    }


    /**
     * 根据类型创建地图
     * @param {number} e - 输入参数 e
     * @param {number} t - 输入参数 t
     * @param {number} n - 输入参数 n
     */
    chuangjian_ditu_by_leixing(e, t, n) {
        let latticeConfig;
        const self = this;

        if (e === 1) {
            const r = Math.ceil(t / 3);
            const a = parseInt(`100${r}`);
            const instance = AL_GAME_HUA_Instance.Instance;
            const latticeConfigInstance = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance();

            switch (instance.LevelType) {
                case AL_GAME_HUA_Define.Define.LevelType.NORMAL:
                    latticeConfig = latticeConfigInstance.huoqu_wangge_peizhi_by_id(a);
                    break;
                case AL_GAME_HUA_Define.Define.LevelType.CHALLENGE:
                    latticeConfig = latticeConfigInstance.huoqu_tiaozhan_guanqia_peizhi_by_id(a, instance.ChallengeLevel);
                    break;
                case AL_GAME_HUA_Define.Define.LevelType.SPECIAL:
                    latticeConfig = latticeConfigInstance.huoqu_teshu_guanqia_peizhi_by_id(a);
                    break;
                default:
                    break;
            }
        } else {
            const instance = AL_GAME_HUA_Instance.Instance;
            const latticeConfigInstance = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance();

            switch (instance.LevelType) {
                case AL_GAME_HUA_Define.Define.LevelType.NORMAL:
                    latticeConfig = latticeConfigInstance.huoqu_wangge_peizhi_by_id(e);
                    break;
                case AL_GAME_HUA_Define.Define.LevelType.CHALLENGE:
                    latticeConfig = latticeConfigInstance.huoqu_tiaozhan_guanqia_peizhi_by_id(e, instance.ChallengeLevel);
                    break;
                case AL_GAME_HUA_Define.Define.LevelType.SPECIAL:
                    latticeConfig = latticeConfigInstance.huoqu_teshu_guanqia_peizhi_by_id(e);
                    break;
                default:
                    break;
            }
        }

        console.log("latticeConfig:", JSON.stringify(latticeConfig));

        let { list: listConfig, row, col } = latticeConfig;
        this.latticeConfig = latticeConfig;
        listConfig = listConfig.slice();
        this.shezhi_ditu_chicun(row, col);

        let zeroIndexList = [];
        listConfig.forEach((value, index) => {
            if (value === 0) zeroIndexList.push(index);
        });

        if (n > 0) {
            zeroIndexList.huoqu_shuzu_suiji_zhiding_shuliang_buchongfu_yuansu(n).forEach(index => {
                listConfig[index] = AL_GAME_HUA_Define.Define.LatticeType.LOCK;
            });
        }

        const startPos = cc.v2(-this.mapSize.width / 2, this.mapSize.height / 2);

        for (let colIndex = 0; colIndex < col; colIndex++) {
            this.map_lattice_list[colIndex] = [];
            for (let rowIndex = 0; rowIndex < row; rowIndex++) {
                let latticeType = listConfig[colIndex * row + rowIndex];
                if (latticeType === undefined) {
                    latticeType = AL_GAME_HUA_Define.Define.LatticeType.NULL;
                }
                if (
                    latticeType === AL_GAME_HUA_Define.Define.LatticeType.VIDEO &&
                    AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() <
                    AL_GAME_HUA_GameConst.GameConst.getInstance().video_lattice_unlock
                ) {
                    latticeType = AL_GAME_HUA_Define.Define.LatticeType.NORMAL;
                }

                const lattice = this.chuangjian_wangge_duixiang();
                lattice.init({
                    type: latticeType,
                    onLatticeUnlock: () => {
                        self.yincang_daoju_tishi();
                        self.jiancha_youxi_shifou_bei_kazhu();
                    }
                });

                if (latticeType === AL_GAME_HUA_Define.Define.LatticeType.LOCK) {
                    this.lock_lattice.push(lattice);
                }

                const posX = startPos.x + colIndex * AL_GAME_HUA_Define.Define.LATTICE_WIDTH + AL_GAME_HUA_Define.Define.LATTICE_WIDTH / 2;
                const posY = startPos.y - rowIndex * AL_GAME_HUA_Define.Define.LATTICE_HEIGHT - AL_GAME_HUA_Define.Define.LATTICE_HEIGHT / 2;
                lattice.node.setPosition(posX, posY);
                this.array_lattice_list.push(lattice);
                this.map_lattice_list[colIndex][rowIndex] = lattice;
                lattice.row = rowIndex;
                lattice.col = colIndex;
                lattice.node.zIndex = 10 - rowIndex;
            }
        }

        if (this.lock_lattice.length > 0) {
            this.lock_lattice = this.lock_lattice.upset();
        }

        for (let rowIndex = 0; rowIndex < row; rowIndex++) {
            const groupedLattices = [];
            let groupIndex = 0;

            for (let colIndex = 0; colIndex < col; colIndex++) {
                const lattice = this.map_lattice_list[colIndex][rowIndex];
                if (lattice.type !== AL_GAME_HUA_Define.Define.LatticeType.NULL) {
                    if (lattice.type !== AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                        groupedLattices[groupIndex] = groupedLattices[groupIndex] || [];
                        groupedLattices[groupIndex].push(lattice);
                    } else {
                        const guizi = this.chuangjian_guizi();
                        guizi.x = lattice.node.x;
                        guizi.y = lattice.node.y - 90;
                        guizi.width = (AL_GAME_HUA_Define.Define.LATTICE_WIDTH / 3) * 2;
                        groupIndex = groupedLattices.length;
                    }
                } else {
                    groupIndex = groupedLattices.length;
                }
            }

            for (const group of groupedLattices) {
                if (group.length > 0) {
                    const guizi = this.chuangjian_guizi();
                    let avgX = 0;
                    for (const lattice of group) {
                        avgX += lattice.node.x;
                    }
                    avgX /= group.length;
                    const posY = group[0].node.y - 90;
                    guizi.setPosition(avgX, posY);
                    guizi.width = group.length * AL_GAME_HUA_Define.Define.LATTICE_WIDTH;
                }
            }
        }
    }


    chuangjian_guizi() {
        const guizi = AL_GAME_HUA_GamePool.GamePool.Instance.get("guizi");
        this.node_layer_lattice.addChild(guizi);
        return guizi;
    }
    /**
     * 加载元素的异步函数
     * 该函数异步加载所有元素，根据不同类型的元素进行处理；
     * 并在加载完成后执行相应的回调。
     */
    async yibu_jiazai_yuansu() {
        return new Promise((resolve, reject) => {
            // 打印日志，开始加载所有元素
            Log.ts("@@@加载所有元素");
            Log.ts("@@@前两层元素加载");

            // 使用集合来存储不同类型的元素索引
            const allElementIndices = new Set();  // 所有元素的索引集合
            const elementMap = {};  // 保存元素信息的映射表
            const firstTwoLayerIndices = new Set(); // 第一层和第二层元素的索引集合
            const otherLayerIndices = new Set(); // 其他层元素的索引集合

            // 遍历所有的格子，加载不同的元素
            for (let latticeIndex = 0; latticeIndex < this.array_lattice_list.length; latticeIndex++) {
                const lattice = this.array_lattice_list[latticeIndex];

                // 只对非空的格子进行处理
                if (lattice.type !== AL_GAME_HUA_Define.Define.LatticeType.NULL) {
                    if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                        // 对于普通格子，遍历其中的元素
                        lattice.bianli_yuansu_list((element, idx, depth) => {
                            if (!(element.idx in elementMap)) {
                                elementMap[element.idx] = [];
                            }
                            elementMap[element.idx].push(element);
                            allElementIndices.add(element.idx);
                            depth < 2 ? firstTwoLayerIndices.add(element.idx) : otherLayerIndices.add(element.idx);
                        });
                    } else if (lattice.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                        // 对于单个元素的格子，直接处理
                        lattice.singlePos.forEach((element) => {
                            if (!(element.idx in elementMap)) {
                                elementMap[element.idx] = [];
                            }
                            elementMap[element.idx].push(element);
                            allElementIndices.add(element.idx);
                            firstTwoLayerIndices.add(element.idx);
                        });
                    }
                }
            }

            // 定义一个加载图标的辅助函数
            const loadIcon = async (index) => {
                return new Promise(async (resolveIcon, rejectIcon) => {
                    const spriteFrame = await AL_GAME_HUA_ElementConfig.ElementConfig.getInstance().jiazai_tubiao_icon(index);
                    if (spriteFrame) {
                        elementMap[index].forEach((element) => {
                            if (cc.isValid(element) && element.idx === index) {
                                element.shezhi_sprite_frame(spriteFrame);
                            }
                        });
                        resolveIcon();
                    } else {
                        rejectIcon();
                    }
                });
            };

            // 创建一个任务数组用于处理前两层元素的加载
            const firstTwoLayerTasks = [];
            firstTwoLayerIndices.forEach((index) => {
                firstTwoLayerTasks.push(loadIcon(index));
            });

            // 等待前两层元素加载完成
            Promise.all(firstTwoLayerTasks)
                .then(async () => {
                    Log.te("@@@前两层元素加载");
                    resolve(); // 前两层加载完成，执行resolve

                    // 逐个加载其他层的元素
                    let completedCount = 0;
                    for (let index of otherLayerIndices) {
                        await loadIcon(index);
                        if (++completedCount === otherLayerIndices.size) {
                            Log.te("@@@加载所有元素");
                        }
                    }
                })
                .catch(() => {
                    reject(); // 如果加载失败，则执行reject
                });
        });
    }


    async xianshi_yuansu_list() {
        const showPromises = this.elements.map((element) => element.chuli_chuangjian_zhanshi());
        AL_GAME_HUA_Common.Common.bofang_yinxiao("stick", this);
        return Promise.all(showPromises);
    }
    /**
     * 生成游戏元素
     */
    shengcheng_yuansu() {
        const levelData = this.levelData;
        const elementType = levelData.Type;
        const elementCount = levelData.Number;
        const emptyLattices = levelData.Empty;

        const latticeConfig = this.latticeConfig;
        const displaceBaseRange = latticeConfig.displaceBase;
        const displaceLayerRange = latticeConfig.zhixing_cengji_weiyi_caozuo;
        const displaceMaxRange = latticeConfig.displaceMax;
        const increaseBaseRange = latticeConfig.increaseBase;
        const increaseLayerRange = latticeConfig.increaseLayer;

        const icons = AL_GAME_HUA_ElementConfig.ElementConfig.getInstance().huoqu_tubiao_genju_dengji(elementType);
        const validLattices = this.huoqu_youxiao_de_wangge();
        const normalLattices = validLattices.normals;
        const singleLattices = validLattices.singles;

        if (
            AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() === 1 &&
            AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.NORMAL
        ) {
            const selectedIcons = [];
            for (let index = 0; index < 10; index++) {
                selectedIcons.push(icons[index]);
            }
            const randomIcons = selectedIcons.huoqu_shuzu_suiji_zhiding_shuliang_buchongfu_yuansu(2);
            normalLattices[0].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(randomIcons[0]), 0, 0);
            normalLattices[0].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(randomIcons[0]), 1, 0);
            normalLattices[1].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(randomIcons[1]), 0, 0);
            normalLattices[1].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(randomIcons[1]), 1, 0);
            normalLattices[2].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(randomIcons[1]), 2, 0);
            normalLattices[3].tianjia_yuansu_dao(this.chuangjian_yuansu_duixiang(randomIcons[0]), 1, 0);
            return;
        }

        this.elementAllocator = new AL_GAME_HUA_ElementAllocator.ElementAllocator({
            icons: icons,
            type: elementType,
            count: elementCount
        });

        const calculatedLayers = Math.ceil(elementCount / (3 * 0.7 * normalLattices.length));
        const midLayer = Math.floor((calculatedLayers / 3) * 2);
        const highLayer = Math.floor(calculatedLayers / 3);

        let displaceBase = Math.get_random(displaceBaseRange[0], displaceBaseRange[1]);
        let displaceLayer = Math.get_random(displaceLayerRange[0], displaceLayerRange[1]);
        let increaseBase = Math.get_random(increaseBaseRange[0], increaseBaseRange[1]);
        let displaceMax = Math.max(displaceMaxRange[0], displaceMaxRange[1]);

        const currentDifficulty = AL_GAME_HUA_GameData.GameData.getInstance().huoqu_dangqian_nandu();
        const levelId = AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.SPECIAL
            ? this.levelData.ID
            : AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia();
        const difficultyByLevel = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_nandu_by_guanqia(levelId);
        const levelIncrease = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_guanqia_increase(levelId);

        const totalDifficulty = currentDifficulty + difficultyByLevel;
        displaceBase = Math.min(displaceMax, levelIncrease * displaceBase + totalDifficulty * increaseBase);
        displaceLayer = Math.min(displaceMax, levelIncrease * displaceLayer + totalDifficulty * increaseBase);

        this.difficultConf = {
            displaceBase: displaceBase,
            zhixing_cengji_weiyi_caozuo: displaceLayer,
            displaceMax: displaceMax
        };

        this.recordConf = {
            displaceCount: 0,
            displaceElement: 0,
            layerDisRate: {},
            layerDisCount: {},
            displaceLayers: 0,
            displaceLayerFb: {},
            layerInfos: []
        };

        if (singleLattices.length > 0) {
            this.tianchong_dange_ceng(singleLattices, normalLattices.length + singleLattices.length);
        }

        let currentLayer = 0;
        while (this.elementAllocator.iconsLenght > 0) {
            this.tianchong_wangge_ceng({
                layer: currentLayer,
                normals: normalLattices.slice().upset(),
                empty: emptyLattices,
                space: currentLayer <= highLayer ? 0 : currentLayer <= midLayer ? 1 : 2
            });
            currentLayer++;
        }

        if (AL_GAME_HUA_Instance.Instance.LevelType === AL_GAME_HUA_Define.Define.LevelType.NORMAL) {
            if (
                AL_GAME_HUA_GameConst.GameConst.getInstance().lv2hard_enabled &&
                AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() ===
                AL_GAME_HUA_GameConst.GameConst.getInstance().lv2hard_level
            ) {
                // Do nothing
            } else {
                if (
                    AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() <=
                    AL_GAME_HUA_GameConst.GameConst.getInstance().displaceLevel
                ) {
                    return;
                }
            }
        }

        const totalLayers = currentLayer;
        this.totalLayer = totalLayers;
        this.displaceProducts = [];

        for (let layerIndex = 0; layerIndex < totalLayers; layerIndex++) {
            this.zhixing_cengji_weiyi_caozuo({
                layer: layerIndex,
                normals: normalLattices,
                space: layerIndex <= highLayer ? 0 : layerIndex <= midLayer ? 1 : 2
            });
        }

        const layerInfos = [];
        for (let layerIndex = 0; layerIndex < totalLayers; layerIndex++) {
            const layerInfo = this.jisuan_cengji_xinxi(layerIndex, normalLattices, singleLattices);
            layerInfos.push(layerInfo);
        }
        this.recordConf.layerInfos = layerInfos;
    }

    /**
     * 计算层级信息
     * 
     * @param {number} layer 当前层数
     * @param {Array} t 单层对象数组
     * @param {Array} n 其他层对象数组
     * @returns {Object} 返回层级信息，包括空位数量、空位率、碰撞次数、碰撞率、下一个连接数及其速率
     */
    jisuan_cengji_xinxi(layer, t, n) {
        // 计算总的元素数量
        const totalElements = 3 * t.length + n.length;

        // 合并两个数组
        const combinedArray = [...t, ...n];

        let countOccupied = 0;
        let crashCount = 0;
        let nextConnectCount = 0;
        const indexCountMap = {};
        let totalNextConnects = 0;

        // 遍历合并后的数组
        combinedArray.forEach((element) => {
            const currentLayer = layer === -1 ? element.curLayer : layer;

            if (element.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                if (currentLayer >= element.singlePos.length) {
                    return;
                }

                const pos = element.singlePos[element.singlePos.length - layer - 1];
                if (pos) {
                    countOccupied++;
                    indexCountMap[pos.idx] = (indexCountMap[pos.idx] || 0) + 1;
                }
            } else if (element.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                element.bianli_layer_list((pos) => {
                    countOccupied++;
                    indexCountMap[pos.idx] = (indexCountMap[pos.idx] || 0) + 1;
                }, currentLayer);
            }
        });

        const emptySpaces = totalElements - countOccupied;
        const emptyRate = emptySpaces / totalElements;
        const indexKeys = Object.keys(indexCountMap);

        // 计算碰撞次数
        indexKeys.forEach(key => {
            const count = indexCountMap[key];
            if (count >= 3) {
                crashCount += 3 * Math.floor(count / 3);
            }
        });

        const crashRate = crashCount / totalElements;

        // 计算下一个连接数
        combinedArray.forEach((element) => {
            const nextLayer = layer === -1 ? element.curLayer + 1 : layer + 1;

            if (element.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                if (nextLayer >= element.singlePos.length) {
                    return;
                }

                const pos = element.singlePos[element.singlePos.length - nextLayer - 1];
                if (indexKeys.includes(String(pos.idx))) {
                    nextConnectCount++;
                }
                totalNextConnects++;
            } else if (element.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL) {
                element.bianli_layer_list((pos) => {
                    if (indexKeys.includes(String(pos.idx))) {
                        nextConnectCount++;
                    }
                    totalNextConnects++;
                }, nextLayer);
            }
        });

        return {
            layer,
            empty: emptySpaces,
            emptyRate,
            crashCount,
            crashRate,
            nextConnectCount,
            nextConnectRate: totalNextConnects === 0 ? 0 : nextConnectCount / totalNextConnects
        };
    }

    shuaxin_jindu() {
        const progress = 1 - this.elements.length / this.levelData.Number;
        AL_GAME_HUA_Instance.Instance.Game.gameUI.shuaxin_guanqia_jindu(progress);
    }
    /**
     * 执行层级位移操作
     * @param {Object} e 包含层级和法线的对象
     */
    zhixing_cengji_weiyi_caozuo(e) {
        const { layer, normals } = e;
        const { displaceBase, zhixing_cengji_weiyi_caozuo, displaceMax } = this.difficultConf;

        // 初始化记录配置中的层级位移计数
        this.recordConf.layerDisCount[layer] = 0;

        // 计算当前层的位移率
        const currentDisplaceRate = Math.min(displaceBase + layer * zhixing_cengji_weiyi_caozuo, displaceMax);
        this.recordConf.layerDisRate[layer] = currentDisplaceRate;

        for (let normalIndex = 0; normalIndex < normals.length; normalIndex++) {
            const normal = normals[normalIndex];
            const emptyCount = normal.huoqu_wangge_kong_shuliang(layer);

            // 如果空位数量不是3，则进行位移处理
            if (emptyCount !== 3) {
                const layerIdx = normal.huoqu_layer_suoyin(layer);

                // 检查当前层的索引是否已经处理过，且根据位移率随机决定是否处理
                if (!this.displaceProducts.includes(layerIdx) && Math.random() < currentDisplaceRate / 100) {

                    // 获取位移间隔
                    const displaceInterval = AL_GAME_HUA_LatticeConfig.LatticeConfig.getInstance().huoqu_displace_jiange(e.space);

                    for (let targetLayer = Math.min(layer + displaceInterval, this.totalLayer); targetLayer > layer;) {
                        const emptyList0 = [];
                        const emptyList1 = [];
                        const emptyList2 = [];

                        for (let normalCheckIndex = 0; normalCheckIndex < normals.length; normalCheckIndex++) {
                            const checkNormal = normals[normalCheckIndex];
                            const targetLayerIdx = checkNormal.huoqu_layer_suoyin(targetLayer);

                            if (!this.displaceProducts.includes(targetLayerIdx)) {
                                const targetEmptyCount = checkNormal.huoqu_wangge_kong_shuliang(targetLayer);

                                // 根据空位数量分类存储
                                if (targetEmptyCount === 0) {
                                    emptyList0.push(checkNormal);
                                } else if (targetEmptyCount === 1) {
                                    emptyList1.push(checkNormal);
                                } else if (targetEmptyCount === 2) {
                                    emptyList2.push(checkNormal);
                                }
                            }
                        }

                        const emptyLists = [emptyList0, emptyList1, emptyList2];
                        let potentialTargets = [...emptyLists[emptyCount], ...emptyLists[0], ...emptyLists[1]].filter(Boolean);

                        // 如果有潜在的目标进行位移
                        if (potentialTargets.length > 0) {
                            const chosenTarget = potentialTargets[0];
                            const chosenLayerIdx = chosenTarget.huoqu_layer_suoyin(targetLayer);

                            this.displaceProducts.push(chosenLayerIdx);

                            const elementsAtCurrentLayer = normal.huoqu_yuansiu_b_layer(layer).slice();
                            const elementsAtTargetLayer = chosenTarget.huoqu_yuansiu_b_layer(targetLayer).slice();

                            // 交换元素位置
                            elementsAtCurrentLayer.forEach((element, index) => {
                                if (element) {
                                    this.recordConf.displaceElement++;
                                    chosenTarget.tianjia_yuansu_dao(element, element.posIdx, targetLayer, true);
                                } else {
                                    chosenTarget.huoqu_yuansiu_b_layer(targetLayer)[index] = null;
                                }
                            });

                            elementsAtTargetLayer.forEach((element, index) => {
                                if (element) {
                                    this.recordConf.displaceElement++;
                                    normal.tianjia_yuansu_dao(element, element.posIdx, layer, true);
                                } else {
                                    normal.huoqu_yuansiu_b_layer(layer)[index] = null;
                                }
                            });

                            // 更新记录配置的各种计数
                            this.recordConf.layerDisCount[layer]++;
                            this.recordConf.displaceCount++;

                            const layersDisplaced = targetLayer - layer;
                            this.recordConf.displaceLayers += layersDisplaced;

                            if (!this.recordConf.displaceLayerFb.hasOwnProperty(layersDisplaced)) {
                                this.recordConf.displaceLayerFb[layersDisplaced] = 0;
                            }

                            this.recordConf.displaceLayerFb[layersDisplaced]++;
                            break;
                        }
                        targetLayer--;
                    }
                }
            }
        }
    }


    tianchong_wangge_ceng(e) {
        const normals = e.normals;
        const emptySlots = e.empty;

        normals.forEach((normal) => {
            this.tianchong_wangge(normal, e.layer, e.space);
        });

        if (e.layer === 0) {
            let totalEmptyCount = 0;
            const groupZero = [];
            const groupOne = [];
            const groupTwo = [];
            const groupThreePlus = [];

            normals.forEach((normal) => {
                const emptyCount = normal.huoqu_wangge_kong_shuliang(0);
                totalEmptyCount += emptyCount;

                switch (emptyCount) {
                    case 0:
                        groupZero.push(normal);
                        break;
                    case 1:
                        groupOne.push(normal);
                        break;
                    case 2:
                        groupTwo.push(normal);
                        break;
                    default:
                        groupThreePlus.push(normal);
                        break;
                }
            });

            if (totalEmptyCount < emptySlots) {
                let combinedGroup = [...groupZero.slice().upset(), ...groupOne.slice().upset()];
                for (let index = 0; totalEmptyCount < emptySlots && combinedGroup.length > 0;) {
                    const normal = combinedGroup[index % combinedGroup.length];
                    const removedElement = normal.yichu_yuansu_suiji();

                    if (removedElement) {
                        this.elementAllocator.tianjia_tubiao(removedElement.idx);
                        AL_GAME_HUA_GamePool.GamePool.Instance.put(removedElement.node);
                        this.yichu_yuansu(removedElement);
                        totalEmptyCount++;

                        if (normal.huoqu_wangge_kong_shuliang() >= 2) {
                            combinedGroup = combinedGroup.filter(item => item !== normal);
                        } else {
                            index++;
                        }
                    } else {
                        combinedGroup = combinedGroup.filter(item => item !== normal);
                    }
                }
            } else if (totalEmptyCount > emptySlots) {
                let combinedGroup = [...groupThreePlus.slice().upset(), ...groupTwo.slice().upset(), ...groupOne.slice().upset()];
                for (let index = 0; totalEmptyCount > emptySlots && this.elementAllocator.iconsLenght !== 0;) {
                    const normal = combinedGroup[index % combinedGroup.length];
                    if (this.changshi_qiangzhi_tianchong_wangge(normal, e.layer)) {
                        totalEmptyCount--;
                    }
                    index++;
                }
            }
        }
    }
    /**
     * 填充网格
     * 根据给定的等级数据和概率生成元素并填充到指定的网格位置。
     *
     * @param {Object} grid 网格对象，提供push_Element和get_Lattice_State方法
     * @param {Number} position 网格中的位置，用于插入元素
     * @param {Number} index 等级数据的索引，用于获取概率和配置
     */
    tianchong_wangge(grid, position, index) {
        const levelData = this.levelData;
        const nullLevel0 = levelData.Null0;
        const nullLevel1 = levelData.Null1;
        const nullLevel2 = levelData.Null2;
        const nullLevel3 = levelData.Null3;
        const rates = [nullLevel0[index], nullLevel1[index], nullLevel2[index]];

        const elementAllocator = this.elementAllocator;
        const rate = this.huoqu_jisuan_gailv_genju_liebiao(rates);

        if (rate === 0) {
            if (Math.random() < nullLevel3[index]) {
                const doubleElements = elementAllocator.chazhao_liangge();
                doubleElements.forEach(doubleElement => {
                    const element = this.chuangjian_yuansu_duixiang(doubleElement);
                    grid.charu_yuansu(element, position);
                });
            }

            while (elementAllocator.iconsLenght !== 0) {
                const latticeState = grid.huoqu_wangge_zhuangtai(position);
                const { total, isDouble, set } = latticeState;

                if (total === 3) {
                    break;
                }

                if (total === 1 || total === 0) {
                    const singleElement = elementAllocator.chazhao_dange(...Array.from(set));
                    if (singleElement) {
                        const element = this.chuangjian_yuansu_duixiang(singleElement);
                        grid.charu_yuansu(element, position);
                    }
                } else if (total === 2) {
                    let singleElement;
                    if (isDouble) {
                        const elementsByLayer = grid.huoqu_yuansiu_b_layer(position);
                        const idx = elementsByLayer[0]?.idx || elementsByLayer[1]?.idx || elementsByLayer[2]?.idx;
                        singleElement = elementAllocator.chazhao_dange(idx);
                        if (singleElement === idx) {
                            elementAllocator.tianjia_tubiao(idx);
                            singleElement = null;
                        }
                    } else {
                        singleElement = elementAllocator.chazhao_dange(...Array.from(set));
                    }

                    if (singleElement) {
                        const element = this.chuangjian_yuansu_duixiang(singleElement);
                        grid.charu_yuansu(element, position);
                    }
                    break;
                }
            }
        } else if (rate === 1) {
            if (Math.random() < nullLevel3[index]) {
                const doubleElements = elementAllocator.chazhao_liangge();
                doubleElements.forEach(doubleElement => {
                    const element = this.chuangjian_yuansu_duixiang(doubleElement);
                    grid.charu_yuansu(element, position);
                });
            }

            while (elementAllocator.iconsLenght !== 0) {
                const latticeState = grid.huoqu_wangge_zhuangtai(position);
                const { total, set } = latticeState;

                if (total >= 2) {
                    break;
                }

                const singleElement = elementAllocator.chazhao_dange(...Array.from(set));
                if (singleElement) {
                    const element = this.chuangjian_yuansu_duixiang(singleElement);
                    grid.charu_yuansu(element, position);
                }
            }
        } else if (rate === 2) {
            const singleElement = elementAllocator.chazhao_dange(-1);
            if (singleElement) {
                const element = this.chuangjian_yuansu_duixiang(singleElement);
                grid.charu_yuansu(element, position);
            }
        }
    }

    /**
     * 尝试强制填充一个格子
     * @param {Object} lattice - 格子对象
     * @param {number} layer - 层级
     * @returns {boolean} 是否成功填充
     */
    changshi_qiangzhi_tianchong_wangge(lattice, layer) {
        const latticeState = lattice.huoqu_wangge_zhuangtai(layer);
        const totalElements = latticeState.total;
        const isDouble = latticeState.isDouble;

        // 如果格子中只有一个元素，尝试填充一个新的元素
        if (totalElements === 1) {
            const elementId = this.elementAllocator.chazhao_dange(-1);
            if (elementId) {
                const element = this.chuangjian_yuansu_duixiang(elementId);
                lattice.charu_yuansu(element, layer);
                return true;
            }
        }

        // 如果格子中有两个元素，尝试根据条件填充一个新的元素
        if (totalElements === 2) {
            let elementId;
            if (isDouble) {
                const elements = lattice.huoqu_yuansiu_b_layer(layer);
                const idx = elements[0]?.idx || elements[1]?.idx || elements[2]?.idx;
                elementId = this.elementAllocator.chazhao_dange(idx);
            } else {
                elementId = this.elementAllocator.chazhao_dange(-1);
            }

            if (elementId) {
                const element = this.chuangjian_yuansu_duixiang(elementId);
                lattice.charu_yuansu(element, layer);
                return true;
            }
        }

        return false;
    }

    /**
     * 填充单层
     * @param {Array} layers - 所有层的数组
     * @param {number} count - 填充数量
     */
    tianchong_dange_ceng(layers, count) {
        const allocator = this.elementAllocator;
        const icons = allocator.icons;

        // 确保要填充的数量不超过图标总数的三分之一
        if (3 * count > icons.length) {
            count = Math.floor(icons.length / 3);
        }

        const layerGroups = [];
        for (let r = 0; r < 3; r++) {
            layerGroups[r] = [];
            for (let index = r * count; index < (r + 1) * count && index < icons.length; index++) {
                layerGroups[r].push(index);
            }
        }

        // 从最上层开始填充
        for (let r = 2; r >= 0; r--) {
            const shuffledLayer = layerGroups[r].slice().sort(() => Math.random() - 0.5); // 随机打乱顺序
            const shuffledLayers = layers.slice().sort(() => Math.random() - 0.5);

            for (let a = 0; a < shuffledLayers.length; a++) {
                const currentLayer = shuffledLayers[a];
                if (a >= shuffledLayer.length) {
                    break;
                }
                const icon = allocator.tanchu_tubiao(allocator.iconsMap[shuffledLayer[a]]);
                if (icon) {
                    const element = this.chuangjian_yuansu_duixiang(icon);
                    currentLayer.charu_yuansu_to_single(element);
                }
            }
        }

        // 更新每一层的UI显示和进度
        layers.forEach(layer => {
            layer.shuaxin_single_zuobiao();
            layer.shezhi_single_jindu();
            layer.singlePos.forEach((pos, index) => {
                pos.shezhi_zhanshi_leixing(layer.singlePos.length - index - 1);
                pos.shizhi_weizhi(1);
            });
        });
    }

    /**
     * 根据列表计算概率返回索引
     * @param {Array} weights - 权重列表
     * @returns {number} 选中的索引
     */
    huoqu_jisuan_gailv_genju_liebiao(weights) {
        const totalWeight = weights.reduce((accumulator, current) => accumulator + current, 0);
        const randomValue = Math.random() * totalWeight;
        let cumulativeWeight = 0;

        for (let index = 0; index < weights.length; index++) {
            cumulativeWeight += weights[index];
            if (randomValue <= cumulativeWeight) {
                return index;
            }
        }

        return 0;
    }
    /**
     * 获取有效的棋格
     * @returns {Object} 包含普通和单一类型的棋格数组
     */
    huoqu_youxiao_de_wangge() {
        const normalLattices = [];
        const singleLattices = [];
        this.array_lattice_list.forEach((currentLattice) => {
            if (currentLattice.type === AL_GAME_HUA_Define.Define.LatticeType.SINGLE) {
                singleLattices.push(currentLattice);
            } else if (currentLattice.type === AL_GAME_HUA_Define.Define.LatticeType.NORMAL && !currentLattice.isVideoLock) {
                normalLattices.push(currentLattice);
            }
        });
        return { normals: normalLattices, singles: singleLattices };
    }

    /**
     * 将位置转换为棋格
     * @param {cc.Vec2} position - 位置向量
     * @returns {Object|null} 对应的棋格对象或空
     */
    weizhi_zhuanhuan_dao_wangge(position) {
        const localPosition = position;
        const mapOrigin = cc.v2(-this.mapSize.width / 2, this.mapSize.height / 2);
        const column = Math.floor((localPosition.x - mapOrigin.x) / AL_GAME_HUA_Define.Define.LATTICE_WIDTH);
        const row = Math.floor((mapOrigin.y - localPosition.y) / AL_GAME_HUA_Define.Define.LATTICE_HEIGHT);

        if (column < 0 || column >= this.map_lattice_list.length || row < 0 || row >= this.map_lattice_list[0].length) {
            return null;
        }

        const targetLattice = this.map_lattice_list[column][row];
        const worldPosition = this.node.convertToWorldSpaceAR(position);
        return targetLattice.jiancha_hit(worldPosition) ? targetLattice : null;
    }

    /**
     * 创建棋格对象
     * @returns {Object} 创建的棋格对象
     */
    chuangjian_wangge_duixiang() {
        const latticeComponent = AL_GAME_HUA_GamePool.GamePool.Instance.get("lattice").getComponent(AL_GAME_HUA_Lattice.default);
        this.node_layer_lattice.addChild(latticeComponent.node);
        return latticeComponent;
    }

    /**
     * 创建元素对象
     * @param {Number} index - 元素索引
     * @returns {Object} 创建的元素对象
     */
    chuangjian_yuansu_duixiang(index) {
        const elementComponent = AL_GAME_HUA_GamePool.GamePool.Instance.get("element").getComponent(AL_GAME_HUA_Element.default);
        this.node_layer_element.addChild(elementComponent.node);
        elementComponent.idx = index;
        this.elements.push(elementComponent);

        if (!(index in this.map_element_list)) {
            this.map_element_list[index] = [];
        }

        this.map_element_list[index].push(elementComponent);
        return elementComponent;
    }

    onDestroy() {
        AL_APP_SDK_MANAGER.nodePoolManager.shanchu_pool("element");
    }
}

exports.default = Game;


